@senad-d/drawme 0.1.4 → 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 +33 -0
- package/README.md +27 -20
- package/assets/references/troubleshooting.md +2 -2
- package/assets/references/xml-authoring.md +5 -9
- package/docs/{agent-guide.md → reference.md} +47 -126
- package/docs/visual-review-implementation-tasks.md +1 -1
- package/example/drawme-extension-waterfall-overview.drawio +72 -0
- package/example/drawme-how-it-works.drawio +124 -80
- package/example/drawme-installation-guide.drawio +95 -67
- package/package.json +1 -1
- package/src/fitcanvas.ts +172 -0
- package/src/geometry.ts +259 -0
- package/src/index.ts +88 -14
- package/src/validate.ts +18 -225
- package/src/workflow.ts +81 -31
package/src/validate.ts
CHANGED
|
@@ -6,18 +6,30 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import { readFile } from "node:fs/promises";
|
|
8
8
|
import { DOMParser } from "@xmldom/xmldom";
|
|
9
|
-
import { type DomEl, attr, childrenByTag, directText,
|
|
9
|
+
import { type DomEl, attr, childrenByTag, directText, firstByTag } from "./dom";
|
|
10
|
+
import {
|
|
11
|
+
type ById,
|
|
12
|
+
type ContentBounds,
|
|
13
|
+
type Point,
|
|
14
|
+
type Rect,
|
|
15
|
+
absRect,
|
|
16
|
+
collectCells,
|
|
17
|
+
contentBounds,
|
|
18
|
+
edgeRoute,
|
|
19
|
+
geometryIsRelative,
|
|
20
|
+
hasInvalidNumber,
|
|
21
|
+
isEdgeLabel,
|
|
22
|
+
isVisible,
|
|
23
|
+
pyFloat,
|
|
24
|
+
rect,
|
|
25
|
+
styleNum,
|
|
26
|
+
} from "./geometry";
|
|
10
27
|
|
|
11
28
|
const RESERVED = new Set(["0", "1"]);
|
|
12
29
|
export const MIN_OUTER_MARGIN = 20;
|
|
13
30
|
const EXCESSIVE_CANVAS_AREA_RATIO = 4;
|
|
14
31
|
const EXCESSIVE_CANVAS_AXIS_RATIO = 0.6;
|
|
15
32
|
|
|
16
|
-
/** [x, y, width, height]. width/height may be NaN when the source omits them. */
|
|
17
|
-
type Rect = [number, number, number, number];
|
|
18
|
-
type Point = [number, number];
|
|
19
|
-
type ById = Map<string, DomEl>;
|
|
20
|
-
|
|
21
33
|
export interface ValidateResult {
|
|
22
34
|
errors: string[];
|
|
23
35
|
warnings: string[];
|
|
@@ -27,180 +39,21 @@ export interface ValidateResult {
|
|
|
27
39
|
score: { total: number; through: number; crossings: number; overlaps: number };
|
|
28
40
|
}
|
|
29
41
|
|
|
30
|
-
/** Python `float()` semantics: accepts nan/inf, strict-numeric otherwise; else undefined (≈ ValueError). */
|
|
31
|
-
function pyFloat(s: string): number | undefined {
|
|
32
|
-
const t = s.trim().toLowerCase();
|
|
33
|
-
if (t === "nan" || t === "+nan" || t === "-nan") return Number.NaN;
|
|
34
|
-
if (t === "inf" || t === "+inf" || t === "infinity" || t === "+infinity") return Infinity;
|
|
35
|
-
if (t === "-inf" || t === "-infinity") return -Infinity;
|
|
36
|
-
if (!/^[+-]?(\d+(\.\d*)?|\.\d+)([eE][+-]?\d+)?$/.test(t)) return undefined;
|
|
37
|
-
const n = Number(t);
|
|
38
|
-
return Number.isNaN(n) ? undefined : n;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
42
|
/** Quote an optional attribute consistently in diagnostic messages. */
|
|
42
43
|
function repr(s: string | null): string {
|
|
43
44
|
return s === null ? "None" : `'${s}'`;
|
|
44
45
|
}
|
|
45
46
|
|
|
46
|
-
function rect(cell: DomEl): Rect | null {
|
|
47
|
-
const gy = firstByTag(cell, "mxGeometry");
|
|
48
|
-
if (!gy) return null;
|
|
49
|
-
const x = pyFloat(attr(gy, "x") ?? "0");
|
|
50
|
-
const y = pyFloat(attr(gy, "y") ?? "0");
|
|
51
|
-
const w = pyFloat(attr(gy, "width") ?? "nan");
|
|
52
|
-
const h = pyFloat(attr(gy, "height") ?? "nan");
|
|
53
|
-
if (x === undefined || y === undefined || w === undefined || h === undefined) return null;
|
|
54
|
-
return [x, y, w, h];
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
function hasInvalidNumber(values: number[]): boolean {
|
|
58
|
-
return values.some((value) => !Number.isFinite(value));
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
function geometryIsRelative(cell: DomEl): boolean {
|
|
62
|
-
return firstByTag(cell, "mxGeometry")?.getAttribute("relative") === "1";
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/** True for separate edge-label vertices. */
|
|
66
|
-
function isEdgeLabel(cell: DomEl): boolean {
|
|
67
|
-
return (attr(cell, "style") ?? "").includes("edgeLabel");
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
function isVisible(cell: DomEl, byId: ById): boolean {
|
|
71
|
-
let current: DomEl | undefined = cell;
|
|
72
|
-
const seen = new Set<string>();
|
|
73
|
-
while (current) {
|
|
74
|
-
if (attr(current, "visible") === "0") return false;
|
|
75
|
-
const parent = attr(current, "parent");
|
|
76
|
-
if (!parent || seen.has(parent)) break;
|
|
77
|
-
seen.add(parent);
|
|
78
|
-
current = byId.get(parent);
|
|
79
|
-
}
|
|
80
|
-
return true;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
47
|
function overlap(a: Rect, b: Rect): boolean {
|
|
84
48
|
const [ax, ay, aw, ah] = a;
|
|
85
49
|
const [bx, by, bw, bh] = b;
|
|
86
50
|
return ax < bx + bw && bx < ax + aw && ay < by + bh && by < ay + ah;
|
|
87
51
|
}
|
|
88
52
|
|
|
89
|
-
function styleNum(style: string | null, key: string): number | undefined {
|
|
90
|
-
for (const part of (style ?? "").split(";")) {
|
|
91
|
-
if (part.startsWith(key + "=")) return pyFloat(part.split("=").slice(1).join("="));
|
|
92
|
-
}
|
|
93
|
-
return undefined;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
53
|
function styleHas(style: string | null, key: string, expected: string): boolean {
|
|
97
54
|
return (style ?? "").split(";").includes(`${key}=${expected}`);
|
|
98
55
|
}
|
|
99
56
|
|
|
100
|
-
/** Absolute (x, y, w, h) of a non-relative vertex, summing parent-container offsets. */
|
|
101
|
-
function absRect(cell: DomEl, byId: ById): Rect | null {
|
|
102
|
-
const r = rect(cell);
|
|
103
|
-
if (r === null || hasInvalidNumber(r)) return null;
|
|
104
|
-
let [x, y] = r;
|
|
105
|
-
const [, , w, h] = r;
|
|
106
|
-
let parent = attr(cell, "parent");
|
|
107
|
-
const seen = new Set<string>();
|
|
108
|
-
while (parent && byId.has(parent) && !seen.has(parent)) {
|
|
109
|
-
seen.add(parent);
|
|
110
|
-
const p = byId.get(parent)!;
|
|
111
|
-
if (p.getAttribute("vertex") === "1" && !geometryIsRelative(p)) {
|
|
112
|
-
const pr = rect(p);
|
|
113
|
-
if (pr && !hasInvalidNumber(pr)) {
|
|
114
|
-
x += pr[0];
|
|
115
|
-
y += pr[1];
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
parent = attr(p, "parent");
|
|
119
|
-
}
|
|
120
|
-
return [x, y, w, h];
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
/** Absolute point where `edge` meets its source/target vertex (honours exit/entry). */
|
|
124
|
-
function endpoint(edge: DomEl, end: "source" | "target", byId: ById): Point | null {
|
|
125
|
-
const vid = attr(edge, end);
|
|
126
|
-
if (!vid || !byId.has(vid)) return null;
|
|
127
|
-
const box = absRect(byId.get(vid)!, byId);
|
|
128
|
-
if (box === null) return null;
|
|
129
|
-
const [x, y, w, h] = box;
|
|
130
|
-
const style = attr(edge, "style") ?? "";
|
|
131
|
-
const fx = styleNum(style, end === "source" ? "exitX" : "entryX");
|
|
132
|
-
const fy = styleNum(style, end === "source" ? "exitY" : "entryY");
|
|
133
|
-
return [x + (fx ?? 0.5) * w, y + (fy ?? 0.5) * h];
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
function edgeWaypoints(edge: DomEl): Point[] {
|
|
137
|
-
const gy = firstByTag(edge, "mxGeometry");
|
|
138
|
-
if (!gy) return [];
|
|
139
|
-
const arr = firstByTag(gy, "Array");
|
|
140
|
-
if (!arr) return [];
|
|
141
|
-
const points: Point[] = [];
|
|
142
|
-
for (const point of childrenByTag(arr, "mxPoint")) {
|
|
143
|
-
const x = pyFloat(attr(point, "x") ?? "");
|
|
144
|
-
const y = pyFloat(attr(point, "y") ?? "");
|
|
145
|
-
if (x !== undefined && y !== undefined && Number.isFinite(x) && Number.isFinite(y)) points.push([x, y]);
|
|
146
|
-
}
|
|
147
|
-
return points;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
/** Absolute polyline for a waypointed edge, or null when auto-routed / unresolved. */
|
|
151
|
-
function edgeRoute(edge: DomEl, byId: ById): Point[] | null {
|
|
152
|
-
const waypoints = edgeWaypoints(edge);
|
|
153
|
-
if (waypoints.length === 0) return null;
|
|
154
|
-
const source = endpoint(edge, "source", byId);
|
|
155
|
-
const target = endpoint(edge, "target", byId);
|
|
156
|
-
if (source === null || target === null) return null;
|
|
157
|
-
return [source, ...waypoints, target];
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
function routeMidpoint(points: Point[]): Point {
|
|
161
|
-
const lengths: number[] = [];
|
|
162
|
-
let total = 0;
|
|
163
|
-
for (let i = 0; i < points.length - 1; i++) {
|
|
164
|
-
const length = Math.hypot(points[i + 1][0] - points[i][0], points[i + 1][1] - points[i][1]);
|
|
165
|
-
lengths.push(length);
|
|
166
|
-
total += length;
|
|
167
|
-
}
|
|
168
|
-
let remaining = total / 2;
|
|
169
|
-
for (let i = 0; i < lengths.length; i++) {
|
|
170
|
-
if (remaining <= lengths[i]) {
|
|
171
|
-
const fraction = lengths[i] === 0 ? 0 : remaining / lengths[i];
|
|
172
|
-
return [
|
|
173
|
-
points[i][0] + fraction * (points[i + 1][0] - points[i][0]),
|
|
174
|
-
points[i][1] + fraction * (points[i + 1][1] - points[i][1]),
|
|
175
|
-
];
|
|
176
|
-
}
|
|
177
|
-
remaining -= lengths[i];
|
|
178
|
-
}
|
|
179
|
-
return points.at(-1) ?? [0, 0];
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
/** Conservative box for a separately sized label on an explicitly routed edge. */
|
|
183
|
-
function explicitEdgeLabelRect(cell: DomEl, byId: ById): Rect | null {
|
|
184
|
-
if (!isEdgeLabel(cell)) return null;
|
|
185
|
-
const local = rect(cell);
|
|
186
|
-
const parent = attr(cell, "parent");
|
|
187
|
-
const edge = parent ? byId.get(parent) : undefined;
|
|
188
|
-
if (!local || hasInvalidNumber(local) || edge?.getAttribute("edge") !== "1") return null;
|
|
189
|
-
const route = edgeRoute(edge, byId);
|
|
190
|
-
if (!route) return null;
|
|
191
|
-
const [midX, midY] = routeMidpoint(route);
|
|
192
|
-
const geometry = firstByTag(cell, "mxGeometry");
|
|
193
|
-
const offset = geometry
|
|
194
|
-
? childrenByTag(geometry, "mxPoint").find((point) => attr(point, "as") === "offset")
|
|
195
|
-
: undefined;
|
|
196
|
-
const offsetX = offset ? pyFloat(attr(offset, "x") ?? "0") : 0;
|
|
197
|
-
const offsetY = offset ? pyFloat(attr(offset, "y") ?? "0") : 0;
|
|
198
|
-
if (offsetX === undefined || offsetY === undefined || !Number.isFinite(offsetX) || !Number.isFinite(offsetY)) {
|
|
199
|
-
return null;
|
|
200
|
-
}
|
|
201
|
-
return [midX + offsetX - local[2] / 2, midY + offsetY - local[3] / 2, local[2], local[3]];
|
|
202
|
-
}
|
|
203
|
-
|
|
204
57
|
function orient(a: Point, b: Point, c: Point): number {
|
|
205
58
|
const value = (b[0] - a[0]) * (c[1] - a[1]) - (b[1] - a[1]) * (c[0] - a[0]);
|
|
206
59
|
if (Math.abs(value) < 1e-9) return 0;
|
|
@@ -308,22 +161,6 @@ function geometryWarnings(cells: DomEl[], ids: ById, parents: Set<string | null>
|
|
|
308
161
|
return [...routeThroughWarnings(routed, leaves), ...routeCrossWarnings(routed)];
|
|
309
162
|
}
|
|
310
163
|
|
|
311
|
-
/** Fold UserObject/object wrappers into their inner mxCell so wrapper ids resolve. */
|
|
312
|
-
function collectCells(root: DomEl | null): DomEl[] {
|
|
313
|
-
const cells: DomEl[] = [];
|
|
314
|
-
for (const child of root ? elemChildren(root) : []) {
|
|
315
|
-
if (child.tagName === "mxCell") cells.push(child);
|
|
316
|
-
else if (child.tagName === "UserObject" || child.tagName === "object") {
|
|
317
|
-
const inner = firstByTag(child, "mxCell");
|
|
318
|
-
if (inner) {
|
|
319
|
-
inner.setAttribute("id", attr(child, "id") ?? "");
|
|
320
|
-
cells.push(inner);
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
return cells;
|
|
325
|
-
}
|
|
326
|
-
|
|
327
164
|
/** Map every cell by id (blank key for id-less cells); report duplicate ids as errors. */
|
|
328
165
|
function buildIds(cells: DomEl[], errors: string[]): ById {
|
|
329
166
|
const ids: ById = new Map();
|
|
@@ -443,50 +280,6 @@ function containmentWarnings(cells: DomEl[], ids: ById): string[] {
|
|
|
443
280
|
.filter((warning): warning is string => warning !== null);
|
|
444
281
|
}
|
|
445
282
|
|
|
446
|
-
interface ContentBounds {
|
|
447
|
-
minX: number;
|
|
448
|
-
minY: number;
|
|
449
|
-
maxX: number;
|
|
450
|
-
maxY: number;
|
|
451
|
-
}
|
|
452
|
-
|
|
453
|
-
function addRectToBounds(bounds: ContentBounds | null, box: Rect): ContentBounds {
|
|
454
|
-
const [x, y, width, height] = box;
|
|
455
|
-
const next = bounds ?? { minX: x, minY: y, maxX: x + width, maxY: y + height };
|
|
456
|
-
next.minX = Math.min(next.minX, x);
|
|
457
|
-
next.minY = Math.min(next.minY, y);
|
|
458
|
-
next.maxX = Math.max(next.maxX, x + width);
|
|
459
|
-
next.maxY = Math.max(next.maxY, y + height);
|
|
460
|
-
return next;
|
|
461
|
-
}
|
|
462
|
-
|
|
463
|
-
function addPointToBounds(bounds: ContentBounds | null, point: Point): ContentBounds {
|
|
464
|
-
return addRectToBounds(bounds, [point[0], point[1], 0, 0]);
|
|
465
|
-
}
|
|
466
|
-
|
|
467
|
-
function contentRect(cell: DomEl, ids: ById): Rect | null {
|
|
468
|
-
if (cell.getAttribute("vertex") !== "1") return null;
|
|
469
|
-
if (isEdgeLabel(cell)) return explicitEdgeLabelRect(cell, ids);
|
|
470
|
-
if (geometryIsRelative(cell)) return null;
|
|
471
|
-
return absRect(cell, ids);
|
|
472
|
-
}
|
|
473
|
-
|
|
474
|
-
function contentWaypoints(cell: DomEl): Point[] {
|
|
475
|
-
return cell.getAttribute("edge") === "1" ? edgeWaypoints(cell) : [];
|
|
476
|
-
}
|
|
477
|
-
|
|
478
|
-
/** Visible vertices/containers, practical edge-label boxes, and explicit waypoints. */
|
|
479
|
-
function contentBounds(cells: DomEl[], ids: ById): ContentBounds | null {
|
|
480
|
-
let bounds: ContentBounds | null = null;
|
|
481
|
-
for (const cell of cells) {
|
|
482
|
-
if (!isVisible(cell, ids)) continue;
|
|
483
|
-
const box = contentRect(cell, ids);
|
|
484
|
-
if (box && !hasInvalidNumber(box)) bounds = addRectToBounds(bounds, box);
|
|
485
|
-
for (const point of contentWaypoints(cell)) bounds = addPointToBounds(bounds, point);
|
|
486
|
-
}
|
|
487
|
-
return bounds;
|
|
488
|
-
}
|
|
489
|
-
|
|
490
283
|
interface PageSettings {
|
|
491
284
|
enabled: boolean;
|
|
492
285
|
width?: number;
|
package/src/workflow.ts
CHANGED
|
@@ -1,17 +1,64 @@
|
|
|
1
|
+
import type { DrawioInfo } from "./drawio";
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
|
-
* Maximum number of automatic source-correction retries across
|
|
3
|
-
*
|
|
4
|
-
* one targeted edit → validation → replacement preview cycle
|
|
4
|
+
* Maximum number of automatic source-correction retries across the visual
|
|
5
|
+
* review. The initial critique pass and the final holistic confirmation do not
|
|
6
|
+
* consume retries; one targeted edit → validation → replacement preview cycle
|
|
7
|
+
* consumes one.
|
|
5
8
|
*/
|
|
6
9
|
export const AUTOMATIC_CORRECTION_LIMIT = 5;
|
|
7
10
|
|
|
11
|
+
/**
|
|
12
|
+
* Reference file contents pre-loaded by the `/drawme` command handler so the
|
|
13
|
+
* model starts with everything in context instead of reading files itself.
|
|
14
|
+
* A null entry means the packaged file could not be read; the workflow then
|
|
15
|
+
* falls back to a read-the-file instruction for that topic.
|
|
16
|
+
*/
|
|
17
|
+
export interface WorkflowReferences {
|
|
18
|
+
diagramTypes: string | null;
|
|
19
|
+
xmlAuthoring: string | null;
|
|
20
|
+
/** Only provided when the CLI supports Mermaid conversion (v30+). */
|
|
21
|
+
mermaidAuthoring: string | null;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function cliStatus(cli: DrawioInfo): string {
|
|
25
|
+
if (!cli.available) {
|
|
26
|
+
return (
|
|
27
|
+
"1. **CLI status (already checked — do not call `drawio_check`)** — the draw.io CLI is NOT available. " +
|
|
28
|
+
"Still author and validate the `.drawio` XML, tell the user how to install draw.io (macOS: `brew install --cask drawio`; other platforms: https://github.com/jgraph/drawio-desktop/releases) or open the source, and skip conversion, layout, previews, visual review, and exports."
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
const features = cli.supportsMermaid
|
|
32
|
+
? "Mermaid conversion and the ELK auto-layout pass are available (v30+)."
|
|
33
|
+
: "This is below v30: hand-author XML; Mermaid conversion and ELK auto-layout are NOT available.";
|
|
34
|
+
return (
|
|
35
|
+
`1. **CLI status (already checked — do not call \`drawio_check\`)** — draw.io ${cli.version ?? "?"} at \`${cli.binary ?? "?"}\`. ` +
|
|
36
|
+
features
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function referenceSection(title: string, path: string, content: string | null): string[] {
|
|
41
|
+
if (content === null) {
|
|
42
|
+
return [`## Reference: ${title}`, "", `Could not be pre-loaded — read \`${path}\` before relying on it.`, ""];
|
|
43
|
+
}
|
|
44
|
+
return [`## Reference: ${title} (pre-loaded from \`${path}\`)`, "", content.trim(), ""];
|
|
45
|
+
}
|
|
46
|
+
|
|
8
47
|
/**
|
|
9
48
|
* Builds the message the `/drawme` command injects to drive the diagram
|
|
10
49
|
* workflow. It steers the model through authoring, deterministic validation,
|
|
11
|
-
*
|
|
50
|
+
* a critique-first visual review, and autonomous final export — once started,
|
|
51
|
+
* the run never pauses for human input. The CLI check result and the topic
|
|
52
|
+
* references are embedded, so no upfront tool calls or file reads are needed;
|
|
53
|
+
* only the rarely needed troubleshooting reference stays on-demand. The
|
|
54
|
+
* preview tool result states whether the review image is attached, so the
|
|
55
|
+
* review instructions branch on that signal rather than assuming vision.
|
|
12
56
|
*/
|
|
13
|
-
export function drawmeWorkflow(description: string, refDir: string,
|
|
57
|
+
export function drawmeWorkflow(description: string, refDir: string, cli: DrawioInfo, refs: WorkflowReferences): string {
|
|
14
58
|
const quoted = description.replaceAll("\n", "\n> ");
|
|
59
|
+
const mermaidPlanning = refs.mermaidAuthoring !== null || cli.supportsMermaid
|
|
60
|
+
? " If it is a standard type with no custom styling, prefer concise Mermaid converted with `drawio_from_mermaid`; see the Mermaid authoring reference below."
|
|
61
|
+
: "";
|
|
15
62
|
return [
|
|
16
63
|
"# DrawMe — create a diagram",
|
|
17
64
|
"",
|
|
@@ -19,34 +66,37 @@ export function drawmeWorkflow(description: string, refDir: string, agentReferen
|
|
|
19
66
|
"",
|
|
20
67
|
`> ${quoted}`,
|
|
21
68
|
"",
|
|
22
|
-
"
|
|
23
|
-
agentReferencePath +
|
|
24
|
-
"`, the official DrawMe extension reference for agent behavior, tool options, decision rules, and limitations.",
|
|
69
|
+
"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. The references at the end of this message are already loaded: do not re-read those files.",
|
|
25
70
|
"",
|
|
26
|
-
|
|
27
|
-
""
|
|
28
|
-
|
|
29
|
-
"
|
|
30
|
-
refDir +
|
|
31
|
-
"/diagram-types.md`. If it is a standard type with no custom styling and the CLI is v30+, prefer concise Mermaid converted with `drawio_from_mermaid`; read `" +
|
|
32
|
-
refDir +
|
|
33
|
-
"/mermaid-authoring.md`.",
|
|
34
|
-
"3. **Author** — for hand-written XML, first read `" +
|
|
35
|
-
refDir +
|
|
36
|
-
"/xml-authoring.md`. Keep XML uncompressed; never reuse ids `0`/`1`; give every edge `<mxGeometry relative=\"1\" as=\"geometry\"/>`; use `drawio_shapesearch` rather than guessing exact vendor/UML/BPMN/cloud styles. For large graphs (>~15 nodes) on v30+, hand-write nodes and use `drawio_layout`. Treat every write, edit, Mermaid conversion, and layout result as a source edit.",
|
|
71
|
+
cliStatus(cli),
|
|
72
|
+
"2. **Plan** — choose the diagram type, shapes, relationships, and layout direction (LR or TB). Plan generous spacing (200–350px between shapes) and do NOT fix page dimensions up front: the canvas is fitted to the finished content later with `drawio_fit_canvas`. For a specific type (ERD, UML class, sequence, C4, architecture, ML/DL, flowchart, SysML, BPMN, network, swimlane), follow the diagram-types reference below." +
|
|
73
|
+
mermaidPlanning,
|
|
74
|
+
"3. **Author** — for hand-written XML, follow the XML authoring reference below. Keep XML uncompressed; never reuse ids `0`/`1`; give every edge `<mxGeometry relative=\"1\" as=\"geometry\"/>`; use `drawio_shapesearch` rather than guessing exact vendor/UML/BPMN/cloud styles. For large graphs (>~15 nodes) on v30+, hand-write nodes and use `drawio_layout`. Space elements generously rather than packing them, then run `drawio_fit_canvas` after authoring — and again after any Mermaid conversion or layout — so the page wraps the content with a comfortable margin. Treat every write, edit, Mermaid conversion, layout, and canvas-fit result as a source edit.",
|
|
37
75
|
"4. **Validate after every source edit** — call `drawio_validate` immediately after authoring and after every later XML edit, Mermaid conversion, or layout operation. Fix all errors before previewing. Every warning must be either fixed or recorded explicitly as reviewed and acceptable with a reason; unresolved or unreviewed warnings block final export.",
|
|
38
|
-
"5. **
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
|
|
45
|
-
"
|
|
46
|
-
|
|
47
|
-
"",
|
|
48
|
-
"
|
|
76
|
+
"5. **Visual review — critique before editing** — export one holistic preview to `<name>.review.png` with `drawio_export` mode `\"preview\"`. The result text states whether the preview image is attached; follow the matching path:",
|
|
77
|
+
" - **Image attached** — write a structured critique of the render before touching the source. Walk every category in this order and, for each one, either record findings as `category / severity / affected cell ids / fix` or state explicitly why it passes — never conclude the render is fine without walking all four:",
|
|
78
|
+
" 1. **Canvas and composition**: page bounds, outer margins, clipping, excessive empty space, aspect ratio, major alignment, and overall balance.",
|
|
79
|
+
" 2. **Nodes and typography**: shape overlap, label clipping/wrapping, readable font size, contrast, padding, sizing, and alignment. If the 2000px full-diagram preview makes labels unreadable, re-export a focused preview (`width`, `pageIndex`) rather than assuming the typography passes.",
|
|
80
|
+
" 3. **Connectors**: endpoints, arrowheads, stacked lines, crossings, routes through unrelated elements, labels, and routing corridors.",
|
|
81
|
+
" 4. **Semantics**: requested components and relationships, hierarchy, consistency, legends, and grouping.",
|
|
82
|
+
" - **Image NOT attached** — the current model cannot view images. Do not describe or judge renders; review structurally instead: cross-check `drawio_validate` findings and a `drawio_explain` read-back against the user's request. Keep the latest `<name>.review.png` on disk so the user can view it, and state plainly in the summary that rendered inspection was skipped.",
|
|
83
|
+
"6. **Fix and confirm** — resolve critique findings with targeted source edits: after each edit, validate, then re-export a focused preview named for the affected category (`<name>.review-canvas.png`, `<name>.review-nodes.png`, `<name>.review-connectors.png`, or `<name>.review-semantics.png`) and confirm the fix. When elements overlap, are cramped, clipped, or short on margin, never shrink or squeeze elements to fit the page — move them apart, then run `drawio_fit_canvas` to enlarge the canvas around them. When no findings remain, re-export the holistic `<name>.review.png`, re-walk all four categories to confirm nothing regressed, and retain that image for the final report. Each successful preview export automatically removes the previous preview file for the same source, so only the latest review image remains.",
|
|
84
|
+
`7. **Correction limit** — the initial critique pass and the final holistic confirmation do not count against the limit. Across the whole automatic review, allow at most ${AUTOMATIC_CORRECTION_LIMIT} correction retries; one retry is one targeted source-edit → \`drawio_validate\` → replacement-preview cycle. Count retries explicitly. If the limit is reached with a finding unresolved, stop automatic editing, keep the best validated state, and continue to final export — name the unresolved finding and its category plainly in the final report instead of looping or waiting for input.`,
|
|
85
|
+
"8. **No human gate** — the run is fully autonomous: once started, never pause to ask for approval, confirmation, or feedback. When the holistic confirmation is clean (or the correction limit was reached), proceed directly to final export. If the user interrupts with feedback mid-run, treat it as new critique findings: targeted edit, validate, focused confirmation, fresh holistic preview, then continue to export.",
|
|
86
|
+
"9. **Final export** — immediately after the holistic confirmation, call `drawio_export` with `mode: \"final\"` for each requested format (default PNG; SVG/PDF/JPG on request). The first successful final export removes the one remaining latest preview for the same source; do not delete previews yourself or report it as a retained output. Report the `.drawio` source and every final path, retained reviewed warnings, any unresolved finding from the correction limit, and cleanup warnings. Offer `drawio_open` for fine-tuning afterwards.",
|
|
87
|
+
"",
|
|
88
|
+
"Failure handling: several DrawMe tools report failures as a text result beginning with `Export failed`, `Layout failed`, `Mermaid conversion failed`, `Fit canvas failed`, `Explain failed`, or `Open failed` rather than a tool error — always read the result text and treat those as failures. If export fails, read `" +
|
|
49
89
|
refDir +
|
|
50
|
-
"/troubleshooting.md
|
|
90
|
+
"/troubleshooting.md` (the one reference kept on-demand). On draw.io below v30, use hand-authored XML instead of Mermaid conversion or ELK layout, but keep validation, the critique-first review, requested-format handling, and final cleanup unchanged.",
|
|
91
|
+
"",
|
|
92
|
+
"---",
|
|
93
|
+
"",
|
|
94
|
+
"# Packaged references (pre-loaded — do not re-read these files)",
|
|
95
|
+
"",
|
|
96
|
+
...referenceSection("diagram types", `${refDir}/diagram-types.md`, refs.diagramTypes),
|
|
97
|
+
...referenceSection("XML authoring", `${refDir}/xml-authoring.md`, refs.xmlAuthoring),
|
|
98
|
+
...(refs.mermaidAuthoring !== null || cli.supportsMermaid
|
|
99
|
+
? referenceSection("Mermaid authoring", `${refDir}/mermaid-authoring.md`, refs.mermaidAuthoring)
|
|
100
|
+
: []),
|
|
51
101
|
].join("\n");
|
|
52
102
|
}
|