diagram-skill
GitHub用于生成、编辑和验证 draw.io/diagrams.net 图表 XML,支持新建、局部修改及截断续传,并自动构建在线编辑器链接以便用户继续编辑。
触发场景
安装
npx skills add CodingFeng101/CanvasAnvil --skill diagram-skill -g -y
SKILL.md
Frontmatter
{
"name": "diagram-skill",
"description": "Generate, edit, and validate draw.io or diagrams.net diagrams as XML, then open them directly in the draw.io online editor so the user can keep editing there. Use for new diagrams, local XML edits, shape-library diagrams, and truncated XML continuation."
}
Diagram Skill
Trigger
Use when the user asks for a diagram, flowchart, architecture diagram, network diagram, ER diagram, BPMN diagram, or a cloud/infrastructure diagram, or mentions draw.io, diagrams.net, drawio, or a .drawio file.
Order
- Classify the request.
- Read the required references.
- Produce or modify draw.io XML.
- Validate the XML.
- Write the XML to a
.drawiofile when file writes are available. - Build an online editor URL and open it in the agent's built-in browser.
- Return the XML code, the
.drawiopath, and the online editor link.
Classification
prompts/display.md- new diagram
- major rewrite
- major relayout
- any case where local editing is fragile
prompts/edit.md- current XML exists
- change is small and precise
- ids can remain stable
prompts/append.md- earlier XML output was truncated
prompts/router.md- routing decision needed before generation
Required References
references/xml-rules.mdreferences/edit-rules.mdreferences/shape-library-index.mdreferences/shape-libraries/<library>.md
Read the library file before generating any library-backed diagram.
Do not guess undocumented shape-library prefixes or shape names.
XML Contract
- New diagrams should normally produce a full
<mxGraphModel>with<root>. - All
mxCellelements must be direct children of<root>. - Root cells must exist:
<mxCell id="0"/><mxCell id="1" parent="0"/>
- Every id must be unique.
- Every edge
sourceandtargetmust reference existing ids. - Preserve existing ids during local edits unless renaming is explicitly required.
- Escape XML attribute values correctly.
- Do not emit XML comments.
Output Contract
- Prefer complete XML for new diagrams.
- Prefer the smallest safe edit set for local changes, then return the full updated XML.
- Stop at a clean boundary when output length is at risk.
- Continue from the exact next character when appending.
- Return the XML as a code block in chat.
- Write the same XML to
<name>.drawiowhen file writes are available. - Do not produce PNG, SVG, PDF, xmlpng, or metadata artifacts.
- Do not run Playwright and do not install browser dependencies.
Online Editor Handoff
-
Save the XML to a
.drawiofile. -
Build the editor URL:
node skill/diagram-skill/scripts/build-drawio-url.mjs --input path\to\diagram.drawioThe script prints a self-contained
https://app.diagrams.net/?offline=1#R...URL with the diagram compressed inside it. -
Open that URL with the agent's built-in browser tool in a new tab and leave the tab open.
-
Tell the user the diagram is loaded and can be edited directly in the online editor. Do not automate edits.
-
If no browser tool is available, or the page fails to load, give the user the URL and the
.drawiopath instead. -
If the script reports
tooLong, or the browser rejects the URL, fall back to the.drawiofile: openhttps://app.diagrams.netand use File > Open From > Device. -
Re-running the handoff opens a fresh editor tab with the current XML. It does not update a tab the user has already edited; ask before replacing manual changes.
-
Do not ask the user to log in.
app.diagrams.networks without an account.
Scripts
scripts/validate-drawio-xml.mjsscripts/build-drawio-url.mjsvendor/pako_deflate.min.cjs(compression only, no install step)
If the user specifies an output directory or file path, write the .drawio file there.
If the user does not specify an output location, create a new output folder automatically and write the .drawio file there.
Do not write generated artifacts into the skill folder.
Deliverables
Preferred:
- draw.io XML code in chat
<name>.drawio- online editor link (
https://app.diagrams.net/?offline=1#R...)
版本历史
- 27f1aea 当前 2026-11-03 09:19


