feat(diagram): compact cells, position and size as attributes on the mxCell

The model now writes a shape as one self-closing mxCell with x, y, w and h
and an edge as one with source and target; compact-cells.ts fills in
vertex, edge, parent="1" and the mxGeometry element after validation. The
long form stays accepted, so waypoints, edge labels and anything else keep
their mxGeometry. The diagram shown to the model (the system context, the
edit error texts and the MCP get_diagram result) is folded into the same
notation, so the model reads what it is asked to write; the canvas and the
saved file stay standard draw.io XML. Folding then expanding the 652 valid
production diagrams gives the same cells back for every one of them.

The auto-fix gains one step for the slip this notation invites: a missing
closing quote before the self-closing slash (h="112/>).

Prompts and the shared examples use the compact form; the single waypoint
example keeps the long form on purpose.

Measured on the five start-screen examples, same prompt, against the
named-styles build: gpt-6-luna 19% fewer output tokens, Opus 5.5 26% fewer
(35% and 41% against main). Every shape was written compactly on the first
try; edits used it too and all applied.
This commit is contained in:
dayuan.jiang
2026-10-10 20:27:51 +09:00
parent 98f2a4fda6
commit 1c51a9f31f
12 changed files with 438 additions and 74 deletions
@@ -657,6 +657,15 @@ export function autoFixXml(xml: string): { fixed: string; fixes: string[] } {
fixes.push("Fixed malformed attribute quotes")
}
// 6b. Missing closing quote on a numeric attribute right before the
// self-closing slash (h="112/>), which a compact cell ends with. Numbers
// only, so a quote that belongs to a label is never touched.
const quoteBeforeSlash = /=("-?\d+(?:\.\d+)?)\/>/g
if (quoteBeforeSlash.test(fixed)) {
fixed = fixed.replace(quoteBeforeSlash, '=$1"/>')
fixes.push("Added a missing closing quote before />")
}
// 7. Fix malformed closing tags
const malformedClosingTag = /<\/([a-zA-Z][a-zA-Z0-9]*)\s*\/>/g
if (malformedClosingTag.test(fixed)) {