--- name: vsdx-diagram-converter description: Convert diagrams from draw.io/.drawio files, attached images, screenshots, hand-drawn architecture sketches, or Mermaid source into editable Microsoft Visio .vsdx files. Use when Codex needs to create, reconstruct, or export Visio diagrams from draw.io XML, image references, or Mermaid flowchart/sequenceDiagram text, including requests for editable Visio output, VSDX generation, diagram redraws, or image-to-Visio conversion. --- # VSDX Diagram Converter ## Goal Create editable Visio `.vsdx` diagrams from either: - draw.io / diagrams.net `.drawio` XML files. - Mermaid `graph` / `flowchart` / `sequenceDiagram` source. - An image or screenshot that should be redrawn as Visio shapes, not embedded as a raster image. Prefer Microsoft Visio COM automation on Windows when Visio is installed. Always export a PNG preview when possible and inspect it before delivery. ## Decision Tree 1. If the input is `.drawio` / diagrams.net XML, run `scripts/drawio_to_vsdx.ps1` first. This preserves the original draw.io coordinates, containers, dashed boxes, labels, colors, and connector routes better than Mermaid auto-layout. 2. If the input is Mermaid source, write it to a `.mmd` file and run `scripts/mermaid_to_vsdx.ps1`. 3. If the input is an image, visually identify the diagram objects, then generate a small Visio COM script that recreates boxes, labels, connectors, and arrowheads as editable shapes. 4. If Visio is unavailable, report that true `.vsdx` generation is blocked unless a valid OOXML `.vsdx` package generator is implemented or Visio is made available. Do not silently deliver SVG/PNG as a substitute for `.vsdx`. ## Draw.io Workflow Use the bundled script for draw.io / diagrams.net XML files: ```powershell powershell -NoProfile -ExecutionPolicy Bypass ` -File "\scripts\drawio_to_vsdx.ps1" ` -InputPath ".\diagram.drawio" ` -OutputPath ".\diagram.vsdx" ` -ExportPng ``` The script redraws supported draw.io objects as editable Visio shapes rather than embedding a raster image. It currently handles common architecture-diagram primitives: - rectangles, rounded rectangles, transparent text labels, and grouped shapes; - dashed containers, colored stroke styles, line weights, and rounded borders; - orthogonal or routed connectors using draw.io `sourcePoint`, `targetPoint`, and intermediate `mxPoint` geometry; - start/end arrowheads and connector labels; - vertical text using `textDirection=vertical-rl`. Prefer this workflow for `.drawio` because it keeps the original layout. Only convert draw.io to Mermaid first when the user explicitly wants a simplified graph/flowchart or when the draw.io XML cannot be parsed into editable primitives. Limitations: the script is intended for uncompressed draw.io XML with an embedded `mxGraphModel`; very custom draw.io stencils, images, swimlane-specific behavior, HTML-rich styling, and compressed diagram payloads may need preprocessing or a task-local enhancement. ## Mermaid Workflow Use the bundled script for straightforward Mermaid: ```powershell powershell -NoProfile -ExecutionPolicy Bypass ` -File "\scripts\mermaid_to_vsdx.ps1" ` -InputPath ".\diagram.mmd" ` -OutputPath ".\diagram.vsdx" ` -ExportPng ``` Supported Mermaid subset: - `graph TD`, `graph TB`, `graph LR`, `graph RL` - `flowchart TD`, `flowchart TB`, `flowchart LR`, `flowchart RL` - Simple edges such as `A[Client] --> B[Proxy]`, `A -->|TLS| B`, `A --- B`, `A -.-> B` - `sequenceDiagram` with `participant` / `actor`, messages such as `A->>B: request`, activation bars from `activate` / `deactivate` or `A->>+B` / `B-->>-A`, and inferred basic activation bars when explicit activation syntax is absent. For complex Mermaid syntax, preprocess into the supported subset rather than hand-editing `.vsdx` XML directly. ## Image Workflow When converting an image: 1. Reconstruct the diagram structure: page title, containers, cards, text blocks, arrows, labels, colors, and relative spacing. 2. Create a task-local PowerShell generator that uses Visio COM primitives: - `DrawRectangle` for boxes and containers. - Separate transparent text shapes when text placement needs precision. - `DrawLine` with `BeginArrow` / `EndArrow` for connectors. - ShapeSheet cells for line color, fill color, line weight, rounding, text size, bold, and font. 3. Save the final `.vsdx`, export a `.png` preview, and inspect the preview visually. 4. Deliver both the `.vsdx` and the preview path. State whether the output is fully redrawn/editable or whether any raster image was embedded. Do not use OCR-only extraction as the output. OCR and loaders can help verify text, but the deliverable must be a Visio drawing unless the user explicitly asks for text extraction. ## Validation After generating `.vsdx`: - Verify the file exists and has nonzero length. - Open it as a ZIP package and confirm it contains `visio/document.xml` and at least one `visio/pages/page*.xml`. - Count `