← 返回
未分类 中文

D2 Diagram Creator

Generate D2 diagram code supporting flowcharts, system architecture diagrams, organizational charts, service topology diagrams, state machine diagrams, swiml...
生成 D2 图表代码,支持流程图、系统架构图、组织结构图、服务拓扑图、状态机图、泳道图等。
huta0kj huta0kj 来源
未分类 clawhub v1.0.0 1 版本 99658.7 Key: 无需
★ 0
Stars
📥 292
下载
💾 0
安装
1
版本
#latest

概述

D2 Diagram Creator

Three-agent pipeline for high-quality diagram generation:

AskUserQuestion → Agent 1 (Analyzer) → Agent 2 (Generator) → Agent 3 (Validator)

Each agent is a general-purpose subagent with its own focused instructions. You (the main agent) orchestrate the pipeline — ask the user questions, then spawn agents in sequence, passing outputs forward.


Step 1: Ask Requirements

Use AskUserQuestion to ask all questions at once. Do not split into multiple rounds, do not skip any.

First round (always required)

{
  "questions": [
    {
      "question": "How detailed should the diagram be?",
      "header": "Detail Level",
      "options": [
        { "label": "Core Flow", "description": "5-8 nodes" },
        { "label": "Moderate", "description": "10-15 nodes" },
        { "label": "Full Detail", "description": "Include all details and exception branches" }
      ]
    },
    {
      "question": "What is the layout direction of the diagram?",
      "header": "Layout Direction",
      "options": [
        { "label": "Horizontal", "description": "direction: right, left to right" },
        { "label": "Vertical", "description": "direction: down, top to bottom" }
      ]
    },
    {
      "question": "What format to export as?",
      "header": "Export Format",
      "options": [
        { "label": "D2 Code Only", "description": "No image export" },
        { "label": "SVG", "description": "Vector graphics (recommended)" },
        { "label": "PNG", "description": "Bitmap" },
        { "label": "Preview", "description": "ASCII text" }
      ]
    }
  ]
}

Second round (only when SVG/PNG is selected)

{
  "questions": [
    {
      "question": "Which theme to use?",
      "header": "Theme",
      "options": [
        { "label": "Light Theme", "description": "--theme 0, white background (default)" },
        { "label": "Dark Theme", "description": "--theme 200, dark background" }
      ]
    },
    {
      "question": "Enable hand-drawn sketch style?",
      "header": "Sketch",
      "options": [
        { "label": "No", "description": "Normal style (default)" },
        { "label": "Yes", "description": "--sketch, hand-drawn effect" }
      ]
    },
    {
      "question": "Choose layout engine?",
      "header": "Layout Engine",
      "options": [
        { "label": "dagre", "description": "Default, fast and efficient" },
        { "label": "elk", "description": "Complex diagrams, 100+ nodes" },
        { "label": "tala", "description": "Most powerful, SVG only, requires installation" }
      ]
    }
  ]
}

Only provide 2 theme options (Light/Dark). Do not add colorful, terminal, or other themes.


Step 2: Spawn Analyzer Agent

Use the Agent tool to spawn the requirements analyzer. This agent deeply analyzes the user's request and produces a structured JSON document.

  • subagent_type: general-purpose
  • description: Analyze diagram requirements

The prompt should be:

Read the file at <skill-base-path>/agents/analyzer.md for your instructions.

Analyze this diagram request:

User request: <user's original description>

User preferences:
- Detail level: <answer>
- Layout direction: <answer>
- Export format: <answer>
- Theme: <answer, or "not selected">
- Sketch: <answer, or "not selected">
- Layout engine: <answer, or "not selected">

Return the structured requirements JSON.

Save the returned JSON — you will pass it to the generator agent.


Step 3: Spawn Generator Agent

Use the Agent tool to spawn the D2 code generator.

  • subagent_type: general-purpose
  • description: Generate D2 diagram code

The prompt should be:

Read the file at <skill-base-path>/agents/generator.md for your instructions.

Generate D2 code based on these requirements:

<the requirements JSON from Step 2>

Read the diagram type guide at:
<skill-base-path>/references/diagram-types/<diagram_type>.md

Save the D2 code to a .d2 file (use a descriptive filename).
Return the file path.

Save the returned file path — you will pass it to the validator agent.


Step 4: Spawn Validator Agent

Use the Agent tool to spawn the validator.

  • subagent_type: general-purpose
  • description: Validate and export diagram

The prompt should be:

Read the file at <skill-base-path>/agents/validator.md for your instructions.

Your skill base directory is: <skill-base-path>
The watermark removal script is at: <skill-base-path>/scripts/remove_watermark.py

Validate and export:

D2 file: <path from Step 3>
Requirements: <the requirements JSON>

Export preferences:
- Format: <export_format>
- Theme: <theme or "default">
- Sketch: <sketch or false>
- Layout engine: <engine or "dagre">

Fix any issues and export the final diagram.

Report the validator's summary to the user.


Diagram Types Reference

TypeUse Case
----------------
FlowchartBusiness processes, decision trees, algorithm flows
System ArchitectureComponent relationships, infrastructure, service interactions
Organizational ChartHierarchical structures, reporting relationships
Service TopologyCloud architecture, network topology
State MachineState transitions, workflow states, lifecycles
Swimlane DiagramCross-functional processes, multi-role workflows
Sequence DiagramTime-based interactions, protocol flows
SQL Table DiagramDatabase schemas, ER diagrams
Grid DiagramDashboard layouts, UI prototypes

Prohibitions

  1. Do not skip requirement questions — always ask first
  2. Do not add visual styles unless the user explicitly requests them
  3. Do not add a diagram title unless the user explicitly requests one
  4. Do not skip any of the three agents — the pipeline must run to completion

版本历史

共 1 个版本

  • v1.0.0 当前
    2026-05-07 19:10 安全 安全

安全检测

腾讯云安全 (Keen)

安全,无风险
查看报告

腾讯云安全 (Sanbu)

安全,无风险
查看报告

🔗 相关推荐

ai-agent

self-improving agent

pskoett
捕获经验教训、错误及修正内容,以实现持续改进。适用于以下场景:(1)命令或操作意外失败;(2)用户纠正Claude(如“不,那不对……”“实际上……”);(3)用户请求的功能不存在;(4)外部API或工具出现故障;(5)Claude发现自身
★ 4,081 📥 809,876
ai-agent

Self-Improving + Proactive Agent

ivangdavila
自我反思+自我批评+自我学习+自组织记忆。智能体评估自身工作、发现错误并持续改进。
★ 1,378 📥 320,405
dev-programming

Github

steipete
使用 `gh` CLI 与 GitHub 交互,通过 `gh issue`、`gh pr`、`gh run` 和 `gh api` 管理议题、PR、CI 运行及高级查询。
★ 676 📥 325,408