شعار D2 Convert

D2 Convert

المجتمع
diegomarino
d2-convert

Convert a Mermaid diagram to D2 format

نظرة عامة

الناشرdiegomarino
المستودعclaude-toolshed
اسم المهارةd2-convert
النجوم
58
التفريعات
5
الملفات المرفقة
تعليمات فقط
الروابط
  • تعليمات بصيغة Markdown

    ملف SKILL.md يُحمّله النموذج عند الحاجة، فلا يستهلك توكنات إلا عندما يَرِد طلب ذو صلة فعلًا.

  • تعمل مع أي نموذج لغوي كبير

    مهارات الذكاء الاصطناعي مكتوبة بصيغة Markdown وليست شيفرة خاصة بمزوّد معيّن، لذا تعمل مع GPT أو Claude أو Gemini أو Grok أو نموذج محلي.

  • مكتفية بذاتها

    كل ما يحتاجه النموذج موجود في التعليمات — لا ملفات إضافية لمزامنتها.

  • مفتوحة المصدر

    نشرها diegomarino على GitHub. اطّلع على المصدر قبل تثبيتها.

التثبيت

ثبّت مهارة الذكاء الاصطناعي D2 Convert في TypingMind لاستخدامها مع أي نموذج لغوي كبير، أو أضفها إلى وكيل ذكاء اصطناعي آخر يقرأ SKILL.md.

1

التثبيت في TypingMind

يُثبّت TypingMind المهارة مباشرةً من مجلدها على GitHub — فيقرأ SKILL.md، ويجمع ملفات الموارد في حزمة، ويحفظ النتيجة محليًا.

  1. افتح التطبيق وانتقل إلى الإضافات → المهارات.
  2. اختر «تثبيت من GitHub».
  3. الصق رابط مجلد المهارة الموضّح أدناه وأكّد التثبيت.
    https://github.com/diegomarino/claude-toolshed/tree/main/plugins/d2/skills/d2-convert
  4. فعّل المهارة في كل محادثة تريد إتاحتها فيها.
الإضافات → المهارات → إضافة مهارة → من رابط GitHub، ثم الصق رابط المجلد واضغط على «متابعة».
2

التثبيت في وكيل ذكاء اصطناعي آخر

يمكن لأي وكيل ذكاء اصطناعي يقرأ تنسيق Agent Skills استخدام هذه المهارة — انسخ المجلد إلى مجلد المهارات الخاص بذلك الوكيل.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/diegomarino/claude-toolshed.git /tmp/claude-toolshed
mkdir -p .claude/skills
cp -r /tmp/claude-toolshed/plugins/d2/skills/d2-convert .claude/skills/d2-convert
أعد تشغيل Claude Code بعد النسخ ليتعرّف على المهارة الجديدة.

استخدمها في TypingMind

فعّل D2 Convert في أي محادثة على TypingMind وسيتولى النموذج الباقي. تتضمن مطالبة النظام اسمها ووصفها، وبمجرد ورود طلب ذي صلة، يُحمّل النموذج التعليمات الكاملة تلقائيًا — فلا تحتاج إلى استدعائها يدويًا، ولا تستهلك أي توكنات حتى تُستخدم فعليًا.

يُحمّل النموذج D2 Convert تلقائيًا بمجرد ورود طلب ذي صلة بها.

تعمل مع أي نموذج ذكاء اصطناعي

مهارات الذكاء الاصطناعي هي تعليمات بصيغة Markdown وليست شيفرة خاصة بمزوّد معيّن، لذا لا ترتبط D2 Convert بالنموذج الذي كُتبت له. ثبّتها مرة واحدة في TypingMind واستخدمها مع GPT-5 أو Claude أو Gemini أو Grok أو DeepSeek أو Mistral أو Llama أو نموذج محلي تشغّله بنفسك — كل ذلك باستخدام مفاتيح API الخاصة بك.

  • تُحمَّل عند الحاجة فقط

    تتضمن مطالبة النظام الاسم والوصف فقط. وتُجلب التعليمات عند أول طلب ذي صلة، لذا لا تترتب أي تكلفة على المهارة غير المستخدمة.

  • بدّل النماذج أثناء المحادثة

    لأن المهارة تعليمات وليست شيفرة، فإن تغيير النموذج لا يعطّلها — فالنموذج التالي يقرأ ملف SKILL.md نفسه.

تعليمات المهارة

هذا هو محتوى SKILL.md الذي يُحمّله النموذج. اقرأه قبل التثبيت — فالمهارة عبارة عن تعليمات سيتبعها نموذجك.

/d2-convert

Input: "$ARGUMENTS"

Task

Detect the Mermaid diagram type from the input, apply the appropriate translation rules, and produce valid D2 output using the matching specialist's syntax patterns.


Step 1: Resolve Plugin Path

bash
PLUGIN_DIR=$(find "$HOME/.claude/plugins/cache" -type d -name "d2" -path "*/skills/d2" 2>/dev/null | head -1)

Fallback (dev/repo):

bash
PLUGIN_DIR=$(find "$HOME" -maxdepth 8 -type d -name "d2" -path "*/skills/d2" 2>/dev/null | head -1)

If still empty: stop — "Plugin not found. Is it installed?"


Step 2: Check Dependencies

bash
bash "$PLUGIN_DIR/scripts/ensure-deps.sh"

Step 3: Read Config

Read .claude/d2.json if present. Apply:

  • theme_id (default: 0)
  • layout (default: "dagre")
  • sketch (default: false)
  • output_directory (default: "./diagrams")
  • auto_validate (default: true)
  • auto_render (default: false)

Step 4: Get the Mermaid Input

If $ARGUMENTS is a file path ending in .md or .mmd: read that file and extract the first fenced code block (```mermaid).

If $ARGUMENTS is a raw code block or inline text: use as-is.

If no input: ask the user to paste the Mermaid code.


Step 5: Detect Mermaid Type

Read the first non-blank, non-comment line of the Mermaid code:

First line starts withMermaid typeD2 specialist
flowchart, graphFlowchartd2-architecture
sequenceDiagramSequenced2-sequence
erDiagramEntity-Relationshipd2-er
classDiagramClassd2-class
stateDiagram, stateDiagram-v2StateUnsupported
ganttGanttUnsupported
piePieUnsupported
journeyUser JourneyUnsupported
gitgraph, gitGraphGit GraphUnsupported
mindmapMind MapUnsupported
timelineTimelineUnsupported

Unsupported: Respond with:

"D2 has no native equivalent for {type} diagrams. Supported conversions: flowchart, sequenceDiagram, erDiagram, classDiagram."


Step 6: Apply Translation Rules

Apply the per-type rules below. Read the matching specialist file AFTER translating — it provides the canonical D2 syntax to validate your output against.

Specialist paths:

  • Flowchart → $PLUGIN_DIR/specialists/d2-architecture.md
  • Sequence → $PLUGIN_DIR/specialists/d2-sequence.md
  • ER → $PLUGIN_DIR/specialists/d2-er.md
  • Class → $PLUGIN_DIR/specialists/d2-class.md

Flowchart / Graph

Node shapes:

MermaidD2
A[Text]A: Text
A(Rounded)A: Rounded { shape: oval }
A{Decision}A: Decision { shape: diamond }
A((Circle))A: Circle { shape: circle }
A[(Database)]A: Database { shape: cylinder }
A([Stadium])A: Stadium { shape: oval }
A[/Parallelogram/]A: Parallelogram (no direct equivalent, use default)

Connections:

MermaidD2
A --> BA -> B
A --> B: labelA -> B: label
A --- BA -- B
A -.-> BA -> B { style.stroke-dash: 4 }
A -.-> B: labelA -> B: label { style.stroke-dash: 4 }
A ==> BA -> B { style.stroke-width: 4 }
A --o BA -> B: o (label the relationship type)
A --x BA -> B: x
A <--> BA <-> B

Subgraphs:

# Mermaid
subgraph MyGroup
  A --> B
end

# D2
MyGroup: {
  A -> B
}

If a subgraph has a title different from its ID:

# Mermaid
subgraph sg1["My Title"]

# D2
sg1: My Title {

Label quoting — REQUIRED: D2 interprets { } in edge labels as edge map syntax. Any label containing {, }, (, ), :, ", or ; MUST be wrapped in double quotes:

d2
# WRONG — D2 parses {id, name} as an edge map key
A -> B: POST /users {id, name}

# CORRECT
A -> B: "POST /users {id, name}"

Apply this to every label during conversion. When in doubt, quote it.

Styles: Drop style, classDef, and class directives — translate visual intent using D2 shape or style properties only where semantically meaningful.

Direction:

  • graph TD / flowchart TD → layout-engine: dagre (default, top-down)
  • graph LR / flowchart LR → add direction: right inside each container, or use layout-engine: elk

Sequence Diagram

All content wraps in a top-level shape: sequence_diagram container:

d2
# Mermaid
sequenceDiagram
  participant A
  participant B
  A->>B: Hello
  B-->>A: Hi

# D2
shape: sequence_diagram
A -> B: Hello
B -> A: Hi { style.stroke-dash: 4 }

Message translations:

Mermaid arrowD2
A->>B: msgA -> B: msg
A->B: msgA -> B: msg
A-->>B: msgA -> B: msg { style.stroke-dash: 4 }
A-xB: msgA -> B: msg (note: Mermaid "destroyed" semantic is lost)
A-)B: msgA -> B: msg (async arrow, use plain)

Label quoting in sequences: Message labels containing {, }, (, ), :, or ; MUST be double-quoted:

d2
# WRONG
Client -> Server: POST /login {email, pass}

# CORRECT
Client -> Server: "POST /login {email, pass}"

Participants:

  • Named participant X as Label → use Label as the node identifier in D2 (or alias map manually)
  • actor X → same as participant in D2

Activation bars: No D2 equivalent. Drop activate/deactivate lines.

Notes:

# Mermaid
Note over A: Some note
Note over A,B: Shared note

# D2 — use dot-notation on the actor, NO arrow needed
A."Some note"

Notes spanning two actors can only be attached to one in D2 — attach to the more relevant actor.

Alt / opt / loop blocks → D2 Groups:

Mermaid's alt/else/opt/loop blocks map to D2 named groups. Actors used inside groups must be pre-declared at the top level:

# Mermaid
sequenceDiagram
  participant A
  participant B
  alt valid credentials
    A->>B: success
  else invalid
    A->>B: failure
  end

# D2
shape: sequence_diagram

# Pre-declare actors used in groups
A
B

valid credentials: {
  A -> B: success
}
invalid: {
  A -> B: failure
}

ER Diagram

Each entity becomes a sql_table shape. Fields map from Mermaid type name to D2 name: type.

d2
# Mermaid
erDiagram
  USER {
    int id PK
    string email UK
    string name
  }
  ORDER {
    int id PK
    int user_id FK
    decimal total
  }
  USER ||--o{ ORDER : "places"

# D2
USER: {
  shape: sql_table
  id: int { constraint: primary_key }
  email: string { constraint: unique }
  name: string
}
ORDER: {
  shape: sql_table
  id: int { constraint: primary_key }
  user_id: int { constraint: foreign_key }
  total: decimal
}
USER.id -> ORDER.user_id: places

Constraint mapping:

MermaidD2
PK{ constraint: primary_key }
FK{ constraint: foreign_key }
UK{ constraint: unique }
PK, FK{ constraint: [primary_key; foreign_key] }
(none)(no constraint clause)

Relationship lines: Map to -> between the PK field of the parent and FK field of the child when identifiable. If fields are unclear, connect entity-to-entity with the relationship label:

d2
USER -> ORDER: places

Cardinality annotations — D2 supports crow's foot notation natively via source-arrowhead and target-arrowhead. Map Mermaid cardinality to D2 arrowhead shapes:

MermaidMeaningD2 arrowhead
|oZero or onecf-one
||Exactly onecf-one-required
o{Zero or morecf-many
|{One or morecf-many-required
d2
# Mermaid: USER ||--o{ ORDER : "places"
# D2:
USER.id -> ORDER.user_id: places {
  source-arrowhead.shape: cf-one-required
  target-arrowhead.shape: cf-many
}

Class Diagram

Each class becomes a labeled container. Methods and fields become labeled entries.

d2
# Mermaid
classDiagram
  class Animal {
    +String name
    +speak() void
  }
  class Dog {
    +String breed
    +fetch() void
  }
  Animal <|-- Dog

# D2
Animal: {
  name: String
  speak(): void
}
Dog: {
  breed: String
  fetch(): void
}
Animal -> Dog: extends

Relationship arrows:

MermaidD2 label
`A <-- B` (inheritance)
A *-- B (composition)A -> B: composition
A o-- B (aggregation)A -> B: aggregation
A --> B (association)A -> B
A ..> B (dependency)A -> B: uses { style.stroke-dash: 4 }
`A ..> B` (realization)
A -- B (link)A -- B

Visibility modifiers: Drop +, -, #, ~ prefixes — D2 has no visibility concept. Keep the name and type only.

Stereotypes: <<interface>>, <<abstract>>, <<service>> — append to the container label:

d2
# Mermaid: class Flyable <<interface>>
# D2:
Flyable (interface): {

Namespaces: namespace MyNS { class A } → MyNS: { A: { ... } }


Step 7: Build the vars Block

d2
vars: {
  d2-config: {
    theme-id: {theme_id}
    layout-engine: {layout}
    sketch: {sketch}
  }
}

Place this at the TOP of the output file (before all diagram content).

Exception: ER diagrams — force sketch: false regardless of config (sketch mode breaks sql_table shapes).


Step 8: Validate

bash
d2 validate {output_file}

If validation fails, inspect the error and apply the fix from $PLUGIN_DIR/references/guides/troubleshooting.md. Fix silently and re-validate before reporting to the user.


Step 9: Save Output

Output filename: {original-name}-d2-{YYYYMMDD}.d2

If the input was inline text (no filename): converted-{mermaid-type}-{YYYYMMDD}.d2

Save to OUTPUT_DIR.


Step 10: Render (if enabled)

If auto_render == true:

bash
d2 {output_file} {output_file_without_ext}.svg

Step 11: Report

Converted {mermaid-type} diagram to D2.

  Input:  {source}
  Output: {output_file}
  Render: {svg_path or "not rendered (auto_render=false)"}

Translation notes:
  - {any semantic losses or approximations made}

Always list translation notes — things that could not be converted exactly (activation bars, cardinality notation, style directives, unsupported constructs).


Example

Input:

Output:

d2
vars: {
  d2-config: {
    theme-id: 0
    layout-engine: dagre
    sketch: false
  }
}

shape: sequence_diagram
Client -> Server: POST /login
Server -> Client: 200 JWT { style.stroke-dash: 4 }

Translation notes:

  • participant X as Label aliases resolved: C → Client, S → Server
  • -->> (dashed reply arrow) mapped to { style.stroke-dash: 4 }

الأسئلة الشائعة

ماذا تفعل مهارة الذكاء الاصطناعي D2 Convert؟

Convert a Mermaid diagram to D2 format

لماذا تستخدم D2 Convert على TypingMind؟

لأنك تثبّتها مرة واحدة وتستخدمها مع أي نموذج. مهارة D2 Convert عبارة عن نص Markdown وليست شيفرة خاصة بمزود بعينه، لذا تعمل المهارة نفسها مع GPT-5 أو Claude أو Gemini أو Grok أو نموذج محلي، ويمكنك تبديل النموذج أثناء المحادثة دون تعطّل المهارة. يعمل TypingMind بمفاتيح API الخاصة بك، فتدفع للمزودين مباشرةً بدلًا من اشتراك لكل مقعد، وتبقى مهاراتك ومحادثاتك في مساحة التخزين الخاصة بك.

كيف أثبّت D2 Convert في TypingMind؟

افتح الإضافات → المهارات → التثبيت من GitHub في TypingMind والصق https://github.com/diegomarino/claude-toolshed/tree/main/plugins/d2/skills/d2-convert. يقرأ TypingMind ملف SKILL.md الخاص بها ويثبّتها كمهارة يمكنك تفعيلها لكل محادثة على حدة.

ما نماذج الذكاء الاصطناعي التي يمكنها استخدام D2 Convert؟

أي نموذج تربطه في TypingMind. مهارات الذكاء الاصطناعي عبارة عن تعليمات Markdown وليست شيفرة خاصة بمزود بعينه، لذا يمكن لكل من GPT وClaude وGemini وGrok والنماذج المحلية تحميل هذه المهارة عندما يتوافق الطلب معها.

كم نموذج ذكاء اصطناعي يمكنني استخدامه مع D2 Convert؟

أي عدد تريده. ما دام النموذج يدعم المهارات، يمكنك استخدام D2 Convert معه، سواء كان GPT أو Claude أو Gemini أو Grok أو DeepSeek أو Mistral أو Llama أو غيرها، وكل ذلك على TypingMind باستخدام مفاتيح API الخاصة بك.

هل مهارة الذكاء الاصطناعي D2 Convert مجانية؟

نشرها diegomarino على GitHub. راجع المستودع للاطلاع على شروط الترخيص. لا تدفع إلا لمزود الذكاء الاصطناعي الخاص بك مقابل التوكنات التي تستخدمها.

ما هي مهارات الذكاء الاصطناعي؟

مهارة الذكاء الاصطناعي حزمة تعليمات قابلة لإعادة الاستخدام تعلّم نموذج الذكاء الاصطناعي كيفية تنفيذ مهمة محددة. وتتبع تنسيق Agent Skills المفتوح: ملف SKILL.md يتضمن اسمًا ووصفًا، إلى جانب أي نصوص برمجية أو قوالب أو ملفات مرجعية قد يحتاج إليها النموذج. لا يقرأ النموذج التعليمات إلا عندما يتوافق طلبك مع المهارة، لذا لا تترتب على المهارة المثبتة أي تكلفة حتى تُستخدم.

كيف تختلف مهارات الذكاء الاصطناعي عن الإضافات أو موصلات MCP؟

تمنح الإضافة أو موصل MCP النموذج أدوات جديدة يمكنه استدعاؤها، وهي شيفرة تُنفَّذ في مكان ما وتُرجع نتيجة. أما مهارة الذكاء الاصطناعي فتزوّد النموذج بالمعرفة ومنهجية العمل: كيفية التعامل مع مهمة، والخطوات التي ينبغي اتباعها، وما ينبغي أن تكون عليه المخرجات الجيدة. المهارات عبارة عن نصوص Markdown، لذا لا تحتاج إلى خادم أو مفتاح API أو بيئة تشغيل، وتعمل مع أي نموذج.

عرض الكل

أنشئ مساحة عملك للذكاء الاصطناعي الآن

اشترك في نشرتنا البريدية لتصلك أخبار الميزات الجديدة والهدايا القادمة 👇