@drunkcoding/agents-and-skills 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/.claude-plugin/marketplace.json +26 -0
  2. package/LICENSE +21 -0
  3. package/README.md +50 -0
  4. package/package.json +33 -0
  5. package/plugins/tech-graph/.claude-plugin/plugin.json +17 -0
  6. package/plugins/tech-graph/README.md +66 -0
  7. package/plugins/tech-graph/agents/tech-graph.md +89 -0
  8. package/plugins/tech-graph/commands/tech-graph.md +13 -0
  9. package/plugins/tech-graph/scripts/check-deps.sh +55 -0
  10. package/plugins/tech-graph/skills/tech-graph/LICENSE +21 -0
  11. package/plugins/tech-graph/skills/tech-graph/README.md +555 -0
  12. package/plugins/tech-graph/skills/tech-graph/README.zh.md +514 -0
  13. package/plugins/tech-graph/skills/tech-graph/SKILL.md +559 -0
  14. package/plugins/tech-graph/skills/tech-graph/agents/openai.yaml +4 -0
  15. package/plugins/tech-graph/skills/tech-graph/assets/samples/sample-style1-flat.png +0 -0
  16. package/plugins/tech-graph/skills/tech-graph/assets/samples/sample-style2-dark.png +0 -0
  17. package/plugins/tech-graph/skills/tech-graph/assets/samples/sample-style3-blueprint.png +0 -0
  18. package/plugins/tech-graph/skills/tech-graph/assets/samples/sample-style4-notion.png +0 -0
  19. package/plugins/tech-graph/skills/tech-graph/assets/samples/sample-style5-glass.png +0 -0
  20. package/plugins/tech-graph/skills/tech-graph/assets/samples/sample-style6-claude.png +0 -0
  21. package/plugins/tech-graph/skills/tech-graph/assets/samples/sample-style7-openai.png +0 -0
  22. package/plugins/tech-graph/skills/tech-graph/fixtures/agent-memory-types-style4.json +181 -0
  23. package/plugins/tech-graph/skills/tech-graph/fixtures/api-flow-style7.json +40 -0
  24. package/plugins/tech-graph/skills/tech-graph/fixtures/mem0-style1.json +297 -0
  25. package/plugins/tech-graph/skills/tech-graph/fixtures/microservices-style3.json +64 -0
  26. package/plugins/tech-graph/skills/tech-graph/fixtures/multi-agent-style5.json +45 -0
  27. package/plugins/tech-graph/skills/tech-graph/fixtures/system-architecture-style6.json +48 -0
  28. package/plugins/tech-graph/skills/tech-graph/fixtures/tool-call-style2.json +182 -0
  29. package/plugins/tech-graph/skills/tech-graph/package.json +42 -0
  30. package/plugins/tech-graph/skills/tech-graph/references/icons.md +406 -0
  31. package/plugins/tech-graph/skills/tech-graph/references/style-1-flat-icon.md +108 -0
  32. package/plugins/tech-graph/skills/tech-graph/references/style-2-dark-terminal.md +107 -0
  33. package/plugins/tech-graph/skills/tech-graph/references/style-3-blueprint.md +113 -0
  34. package/plugins/tech-graph/skills/tech-graph/references/style-4-notion-clean.md +95 -0
  35. package/plugins/tech-graph/skills/tech-graph/references/style-5-glassmorphism.md +125 -0
  36. package/plugins/tech-graph/skills/tech-graph/references/style-6-claude-official.md +209 -0
  37. package/plugins/tech-graph/skills/tech-graph/references/style-7-openai.md +215 -0
  38. package/plugins/tech-graph/skills/tech-graph/references/style-diagram-matrix.md +135 -0
  39. package/plugins/tech-graph/skills/tech-graph/references/svg-layout-best-practices.md +100 -0
  40. package/plugins/tech-graph/skills/tech-graph/scripts/README.md +269 -0
  41. package/plugins/tech-graph/skills/tech-graph/scripts/generate-diagram.sh +181 -0
  42. package/plugins/tech-graph/skills/tech-graph/scripts/generate-from-template.py +1587 -0
  43. package/plugins/tech-graph/skills/tech-graph/scripts/test-all-styles.sh +143 -0
  44. package/plugins/tech-graph/skills/tech-graph/scripts/validate-svg.sh +306 -0
  45. package/plugins/tech-graph/skills/tech-graph/templates/agent-architecture.svg +28 -0
  46. package/plugins/tech-graph/skills/tech-graph/templates/architecture.svg +23 -0
  47. package/plugins/tech-graph/skills/tech-graph/templates/comparison-matrix.svg +14 -0
  48. package/plugins/tech-graph/skills/tech-graph/templates/data-flow.svg +28 -0
  49. package/plugins/tech-graph/skills/tech-graph/templates/er-diagram.svg +21 -0
  50. package/plugins/tech-graph/skills/tech-graph/templates/flowchart.svg +21 -0
  51. package/plugins/tech-graph/skills/tech-graph/templates/sequence.svg +20 -0
  52. package/plugins/tech-graph/skills/tech-graph/templates/state-machine.svg +20 -0
  53. package/plugins/tech-graph/skills/tech-graph/templates/timeline.svg +19 -0
  54. package/plugins/tech-graph/skills/tech-graph/templates/use-case.svg +21 -0
@@ -0,0 +1,559 @@
1
+ ---
2
+ name: fireworks-tech-graph
3
+ description: >-
4
+ Use when the user wants to create any technical diagram - architecture, data
5
+ flow, flowchart, sequence, agent/memory, or concept map - and export as
6
+ SVG+PNG. Trigger on: "画图" "帮我画" "生成图" "做个图" "架构图" "流程图"
7
+ "可视化一下" "出图" "generate diagram" "draw diagram" "visualize" or any
8
+ system/flow description the user wants illustrated.
9
+ ---
10
+
11
+ # Fireworks Tech Graph
12
+
13
+ Generate production-quality SVG technical diagrams exported as PNG via `cairosvg` (recommended), `rsvg-convert`, or `puppeteer`.
14
+
15
+ ## Install Source
16
+
17
+ Install this skill from GitHub:
18
+
19
+ ```bash
20
+ npx skills add yizhiyanhua-ai/fireworks-tech-graph
21
+ ```
22
+
23
+ Public package page:
24
+
25
+ ```text
26
+ https://www.npmjs.com/package/@yizhiyanhua-ai/fireworks-tech-graph
27
+ ```
28
+
29
+ Do not pass `@yizhiyanhua-ai/fireworks-tech-graph` directly to `skills add`, because the CLI expects a GitHub or local repository source.
30
+
31
+ Update command:
32
+
33
+ ```bash
34
+ npx skills add yizhiyanhua-ai/fireworks-tech-graph --force -g -y
35
+ ```
36
+
37
+ ## Helper Scripts (Recommended)
38
+
39
+ Four helper scripts in `scripts/` directory provide stable SVG generation and validation:
40
+
41
+ ### 1. `generate-diagram.sh` - Validate SVG + export PNG
42
+ ```bash
43
+ ./scripts/generate-diagram.sh -t architecture -s 1 -o ./output/arch.svg
44
+ ```
45
+ - Validates an existing SVG file
46
+ - Exports PNG after validation
47
+ - Example: `./scripts/generate-diagram.sh -t architecture -s 1 -o ./output/arch.svg`
48
+
49
+ ### 2. `generate-from-template.py` - Create starter SVG from template
50
+ ```bash
51
+ python3 ./scripts/generate-from-template.py architecture ./output/arch.svg '{"title":"My Diagram","nodes":[],"arrows":[]}'
52
+ ```
53
+ - Loads a built-in SVG template
54
+ - Renders nodes, arrows, and legend entries from JSON input
55
+ - Escapes text content to keep output XML-valid
56
+
57
+ ### 3. `validate-svg.sh` - Validate SVG syntax
58
+ ```bash
59
+ ./scripts/validate-svg.sh <svg-file>
60
+ ```
61
+ - Checks XML syntax
62
+ - Verifies tag balance
63
+ - Validates marker references
64
+ - Checks attribute completeness
65
+ - Validates path data
66
+
67
+ ### 4. `test-all-styles.sh` - Batch test all styles
68
+ ```bash
69
+ ./scripts/test-all-styles.sh
70
+ ```
71
+ - Tests multiple diagram sizes
72
+ - Validates all generated SVGs
73
+ - Generates test report
74
+
75
+ **When to use scripts:**
76
+ - Use scripts when generating complex SVGs to avoid syntax errors
77
+ - Scripts provide automatic validation and error reporting
78
+ - Recommended for production diagrams
79
+
80
+ **When to generate SVG directly:**
81
+ - Simple diagrams with few elements
82
+ - Quick prototypes
83
+ - When you need full control over SVG structure
84
+
85
+ ## Workflow (Always Follow This Order)
86
+
87
+ 1. **Classify** the diagram type (see Diagram Types below)
88
+ 2. **Extract structure** — identify layers, nodes, edges, flows, and semantic groups from user description
89
+ 3. **Plan layout** — apply the layout rules for the diagram type
90
+ 4. **Load style reference** — always load `references/style-1-flat-icon.md` unless user specifies another; load the matching `references/style-N.md` for exact color tokens and SVG patterns
91
+ 5. **Map nodes to shapes** — use Shape Vocabulary below
92
+ 6. **Check icon needs** — load `references/icons.md` for known products
93
+ 7. **Write SVG** with adaptive strategy (see SVG Generation Strategy below)
94
+ 8. **Validate**: Run `python3 -c "import xml.etree.ElementTree as ET; ET.parse('file.svg')"` to check XML syntax
95
+ 9. **Export PNG**: Use `cairosvg` (recommended). See **SVG → PNG Conversion** section below for full method comparison
96
+ 10. **Report** the generated file paths
97
+ 11. **(Optional) Visual self-review** — if your runtime can read images, load the exported PNG back and inspect it. Syntactic validity does not guarantee visual correctness: arrows may cross through component interiors, labels may collide with lifelines or other labels, boxes may overlap, alt-frame text may sit on top of a message, or a legend may cover content. If you see any of these, revise the SVG and re-export; repeat until the rendered image is clean. Common fixes:
98
+ - Route arrows through gaps between boxes, not through box interiors
99
+ - Add background rects behind arrow labels (opacity 0.95, matching canvas color)
100
+ - Widen inter-row/inter-column gutters so same-layer arrows have clear corridors
101
+ - Collapse repeated cross-layer arrows into a single "delegates down" rail outside the content area
102
+ - Move legend/notes out of any region where arrows or labels land
103
+ - Increase viewBox height/width rather than packing elements tighter
104
+ Skip this step silently if image reading is unavailable — do not guess.
105
+
106
+ ## Diagram Types & Layout Rules
107
+
108
+ ### Architecture Diagram
109
+ Nodes = services/components. Group into **horizontal layers** (top→bottom or left→right).
110
+ - Typical layers: Client → Gateway/LB → Services → Data/Storage
111
+ - Use `<rect>` dashed containers to group related services in the same layer
112
+ - Arrow direction follows data/request flow
113
+ - ViewBox: `0 0 960 600` standard, `0 0 960 800` for tall stacks
114
+
115
+ ### Data Flow Diagram
116
+ Emphasizes **what data moves where**. Focus on data transformation.
117
+ - Label every arrow with the data type (e.g., "embeddings", "query", "context")
118
+ - Use wider arrows (`stroke-width: 2.5`) for primary data paths
119
+ - Dashed arrows for control/trigger flows
120
+ - Color arrows by data category (not just Agent/RAG — use semantics)
121
+
122
+ ### Flowchart / Process Flow
123
+ Sequential decision/process steps.
124
+ - Top-to-bottom preferred; left-to-right for wide flows
125
+ - Diamond shapes for decisions, rounded rects for processes, parallelograms for I/O
126
+ - Keep node labels short (≤3 words); put detail in sub-labels
127
+ - Align nodes on a grid: x positions snap to 120px intervals, y to 80px
128
+
129
+ ### Agent Architecture Diagram
130
+ Shows how an AI agent reasons, uses tools, and manages memory.
131
+ Key conceptual layers to always consider:
132
+ - **Input layer**: User, query, trigger
133
+ - **Agent core**: LLM, reasoning loop, planner
134
+ - **Memory layer**: Short-term (context window), Long-term (vector/graph DB), Episodic
135
+ - **Tool layer**: Tool calls, APIs, search, code execution
136
+ - **Output layer**: Response, action, side-effects
137
+ Use cyclic arrows (loop arcs) to show iterative reasoning. Separate memory types visually.
138
+
139
+ ### Memory Architecture Diagram (Mem0, MemGPT-style)
140
+ Specialized agent diagram focused on memory operations.
141
+ - Show memory **write path** and **read path** separately (different arrow colors)
142
+ - Memory tiers: Working Memory → Short-term → Long-term → External Store
143
+ - Label memory operations: `store()`, `retrieve()`, `forget()`, `consolidate()`
144
+ - Use stacked rects or layered cylinders for storage tiers
145
+
146
+ ### Sequence Diagram
147
+ Time-ordered message exchanges between participants.
148
+ - Participants as vertical **lifelines** (top labels + vertical dashed lines)
149
+ - Messages as horizontal arrows between lifelines, top-to-bottom time order
150
+ - Activation boxes (thin filled rects on lifeline) show active processing
151
+ - Group with `<rect>` loop/alt frames with label in top-left corner
152
+ - ViewBox height = 80 + (num_messages × 50)
153
+
154
+ ### Comparison / Feature Matrix
155
+ Side-by-side comparison of approaches, systems, or components.
156
+ - Column headers = systems, row headers = attributes
157
+ - Row height: 40px; column width: min 120px; header row height: 50px
158
+ - Checked cell: tinted background (e.g. `#dcfce7`) + `✓` checkmark; unsupported: `#f9fafb` fill
159
+ - Alternating row fills (`#f9fafb` / `#ffffff`) for readability
160
+ - Max readable columns: 5; beyond that, split into two diagrams
161
+
162
+ ### Timeline / Gantt
163
+ Horizontal time axis showing durations, phases, and milestones.
164
+ - X-axis = time (weeks/months/quarters); Y-axis = items/tasks/phases
165
+ - Bars: rounded rects, colored by category, labeled inside or beside
166
+ - Milestone markers: diamond or filled circle at specific x position with label above
167
+ - ViewBox: `0 0 960 400` typical; wider for many time periods: `0 0 1200 400`
168
+
169
+ ### Mind Map / Concept Map
170
+ Radial layout from central concept.
171
+ - Central node at `cx=480, cy=280`
172
+ - First-level branches: evenly distributed around center (360/N degrees)
173
+ - Second-level branches: branch off first-level at 30-45° offset
174
+ - Use curved `<path>` with cubic bezier for branches, not straight lines
175
+
176
+ ### Class Diagram (UML)
177
+ Static structure showing classes, attributes, methods, and relationships.
178
+ - **Class box**: 3-compartment rect (name / attributes / methods), min width 160px
179
+ - Top compartment: class name, bold, centered (abstract = *italic*)
180
+ - Middle: attributes with visibility (`+` public, `-` private, `#` protected)
181
+ - Bottom: method signatures, same visibility notation
182
+ - **Relationships**:
183
+ - Inheritance (extends): solid line + hollow triangle arrowhead, child → parent
184
+ - Implementation (interface): dashed line + hollow triangle, class → interface
185
+ - Association: solid line + open arrowhead, label with multiplicity (1, 0..*, 1..*)
186
+ - Aggregation: solid line + hollow diamond on container side
187
+ - Composition: solid line + filled diamond on container side
188
+ - Dependency: dashed line + open arrowhead
189
+ - **Interface**: `<<interface>>` stereotype above name, or circle/lollipop notation
190
+ - **Enum**: compartment rect with `<<enumeration>>` stereotype, values in bottom
191
+ - Layout: parent classes top, children below; interfaces to the left/right of implementors
192
+ - ViewBox: `0 0 960 600` standard; `0 0 960 800` for deep hierarchies
193
+
194
+ ### Use Case Diagram (UML)
195
+ System functionality from user perspective.
196
+ - **Actor**: stick figure (circle head + body line) placed outside system boundary
197
+ - Label below figure, 13-14px
198
+ - Primary actors on left, secondary/supporting on right
199
+ - **Use case**: ellipse with label centered inside, min 140×60px
200
+ - Keep names verb phrases: "Create Order", "Process Payment"
201
+ - **System boundary**: large rect with dashed border + system name in top-left
202
+ - **Relationships**:
203
+ - Include: dashed arrow `<<include>>` from base to included use case
204
+ - Extend: dashed arrow `<<extend>>` from extension to base use case
205
+ - Generalization: solid line + hollow triangle (specialized → general)
206
+ - Layout: system boundary centered, actors outside, use cases inside
207
+ - ViewBox: `0 0 960 600` standard
208
+
209
+ ### State Machine Diagram (UML)
210
+ Lifecycle states and transitions of an entity.
211
+ - **State**: rounded rect with state name, min 120×50px
212
+ - Internal activities: small text `entry/ action`, `exit/ action`, `do/ activity`
213
+ - **Initial state**: filled black circle (r=8), one outgoing arrow
214
+ - **Final state**: filled circle (r=8) inside hollow circle (r=12)
215
+ - **Choice**: small hollow diamond, guard labels on outgoing arrows `[condition]`
216
+ - **Transition**: arrow with optional label `event [guard] / action`
217
+ - Guard conditions in square brackets
218
+ - Actions after `/`
219
+ - **Composite/nested state**: larger rect containing sub-states, with name tab
220
+ - **Fork/join**: thick horizontal or vertical black bar (synchronization)
221
+ - Layout: initial state top-left, final state bottom-right, flow top-to-bottom
222
+ - ViewBox: `0 0 960 600` standard
223
+
224
+ ### ER Diagram (Entity-Relationship)
225
+ Database schema and data relationships.
226
+ - **Entity**: rect with entity name in header (bold), attributes below
227
+ - Primary key attribute: underlined
228
+ - Foreign key: italic or marked with (FK)
229
+ - Min width: 160px; attribute font-size: 12px
230
+ - **Relationship**: diamond shape on connecting line
231
+ - Label inside diamond: "has", "belongs to", "enrolls in"
232
+ - Cardinality labels near entity: `1`, `N`, `0..1`, `0..*`, `1..*`
233
+ - **Weak entity**: double-bordered rect with double diamond relationship
234
+ - **Associative entity**: diamond + rect hybrid (rect with diamond inside)
235
+ - Line style: solid for identifying relationships, dashed for non-identifying
236
+ - Layout: entities in 2-3 rows, relationships between related entities
237
+ - ViewBox: `0 0 960 600` standard; wider `0 0 1200 600` for many entities
238
+
239
+ ### Network Topology
240
+ Physical or logical network infrastructure.
241
+ - **Devices**: icon-like rects or rounded rects
242
+ - Router: circle with cross arrows
243
+ - Switch: rect with arrow grid
244
+ - Server: stacked rect (rack icon)
245
+ - Firewall: brick-pattern rect or shield shape
246
+ - Load Balancer: horizontal split rect with arrows
247
+ - Cloud: cloud path (overlapping arcs)
248
+ - **Connections**: lines between device centers
249
+ - Ethernet/wired: solid line, label bandwidth
250
+ - Wireless: dashed line with WiFi symbol
251
+ - VPN: dashed line with lock icon
252
+ - **Subnets/Zones**: dashed rect containers with zone label (DMZ, Internal, External)
253
+ - **Labels**: device hostname + IP below, 12-13px
254
+ - Layout: tiered top-to-bottom (Internet → Edge → Core → Access → Endpoints)
255
+ - ViewBox: `0 0 960 600` standard
256
+
257
+ ## UML Coverage Map
258
+
259
+ Full mapping of UML 14 diagram types to supported diagram types:
260
+
261
+ | UML Diagram | Supported As | Notes |
262
+ |-------------|-------------|-------|
263
+ | Class | Class Diagram | Full UML notation |
264
+ | Component | Architecture Diagram | Use colored fills per component type |
265
+ | Deployment | Architecture Diagram | Add node/instance labels |
266
+ | Package | Architecture Diagram | Use dashed grouping containers |
267
+ | Composite Structure | Architecture Diagram | Nested rects within components |
268
+ | Object | Class Diagram | Instance boxes with underlined name |
269
+ | Use Case | Use Case Diagram | Full actor/ellipse/relationship |
270
+ | Activity | Flowchart / Process Flow | Add fork/join bars |
271
+ | State Machine | State Machine Diagram | Full UML notation |
272
+ | Sequence | Sequence Diagram | Add alt/opt/loop frames |
273
+ | Communication | — | Approximate with Sequence (swap axes) |
274
+ | Timing | Timeline | Adapt time axis |
275
+ | Interaction Overview | Flowchart | Combine activity + sequence fragments |
276
+ | ER Diagram | ER Diagram | Chen/Crow's foot notation |
277
+
278
+ ## Shape Vocabulary
279
+
280
+ Map semantic concepts to consistent shapes across all diagram types:
281
+
282
+ | Concept | Shape | Notes |
283
+ |---------|-------|-------|
284
+ | User / Human | Circle + body path | Stick figure or avatar |
285
+ | LLM / Model | Rounded rect with brain/spark icon or gradient fill | Use accent color |
286
+ | Agent / Orchestrator | Hexagon or rounded rect with double border | Signals "active controller" |
287
+ | Memory (short-term) | Rounded rect, dashed border | Ephemeral = dashed |
288
+ | Memory (long-term) | Cylinder (database shape) | Persistent = solid cylinder |
289
+ | Vector Store | Cylinder with grid lines inside | Add 3 horizontal lines |
290
+ | Graph DB | Circle cluster (3 overlapping circles) | |
291
+ | Tool / Function | Gear-like rect or rect with wrench icon | |
292
+ | API / Gateway | Hexagon (single border) | |
293
+ | Queue / Stream | Horizontal tube (pipe shape) | |
294
+ | File / Document | Folded-corner rect | |
295
+ | Browser / UI | Rect with 3-dot titlebar | |
296
+ | Decision | Diamond | Flowcharts only |
297
+ | Process / Step | Rounded rect | Standard box |
298
+ | External Service | Rect with cloud icon or dashed border | |
299
+ | Data / Artifact | Parallelogram | I/O in flowcharts |
300
+
301
+ ## Arrow Semantics
302
+
303
+ Always assign arrow meaning, not just color:
304
+
305
+ | Flow Type | Color | Stroke | Dash | Meaning |
306
+ |-----------|-------|--------|------|---------|
307
+ | Primary data flow | blue `#2563eb` | 2px solid | none | Main request/response path |
308
+ | Control / trigger | orange `#ea580c` | 1.5px solid | none | One system triggering another |
309
+ | Memory read | green `#059669` | 1.5px solid | none | Retrieval from store |
310
+ | Memory write | green `#059669` | 1.5px | `5,3` | Write/store operation |
311
+ | Async / event | gray `#6b7280` | 1.5px | `4,2` | Non-blocking, event-driven |
312
+ | Embedding / transform | purple `#7c3aed` | 1px solid | none | Data transformation |
313
+ | Feedback / loop | purple `#7c3aed` | 1.5px curved | none | Iterative reasoning loop |
314
+
315
+ Always include a **legend** when 2+ arrow types are used.
316
+
317
+ ## Layout Rules & Validation
318
+
319
+ **Spacing**:
320
+ - Same-layer nodes: 80px horizontal, 120px vertical between layers
321
+ - Canvas margins: 40px minimum, 60px between node edges
322
+ - Snap to 8px grid: horizontal 120px intervals, vertical 120px intervals
323
+
324
+ **Arrow Labels** (CRITICAL):
325
+ - MUST have background rect: `<rect fill="canvas_bg" opacity="0.95"/>` with 4px horizontal, 2px vertical padding
326
+ - Place mid-arrow, ≤3 words, stagger by 15-20px when multiple arrows converge
327
+ - Maintain 10px safety distance from nodes
328
+
329
+ **Arrow Routing**:
330
+ - Prefer orthogonal (L-shaped) paths to minimize crossings
331
+ - Anchor arrows on component edges, not geometric centers
332
+ - Route around dense node clusters, use different y-offsets for parallel arrows
333
+ - Jump-over arcs (5px radius) for unavoidable crossings
334
+
335
+ **Line Overlap Prevention** (CRITICAL - most common bug on Codex):
336
+ When two arrows must cross each other, ALWAYS use jump-over arcs to prevent visual overlap:
337
+ - Crossing horizontal arrows: add a small semicircle arc (radius 5px, stroke same color as arrow, fill none) that "jumps over" the other line
338
+ - SVG pattern for jump-over: use a white/matching-background arc on the lower layer, then draw the upper arc on top
339
+ - Multiple crossings: stagger arc radii (5px, 7px, 9px) so arcs don't overlap each other
340
+ - Never let two arrows' straight-line segments cross without a jump-over arc
341
+
342
+ **Validation Checklist** (run before finalizing):
343
+ 1. **Arrow-Component Collision**: Arrows MUST NOT pass through component interiors (route around with orthogonal paths)
344
+ 2. **Text Overflow**: All text MUST fit with 8px padding (estimate: `text.length × 7px ≤ shape_width - 16px`)
345
+ 3. **Arrow-Text Alignment**: Arrow endpoints MUST connect to shape edges (not floating); all arrow labels MUST have background rects
346
+ 4. **Container Discipline**: Prefer arrows entering and leaving section containers through open gaps between components, not through inner component bodies
347
+
348
+ ## SVG Technical Rules
349
+
350
+ - ViewBox: `0 0 960 600` default; `0 0 960 800` tall; `0 0 1200 600` wide
351
+ - Fonts: embed via `<style>font-family: ...</style>` — no external `@import` (cairosvg / rsvg-convert cannot fetch external URLs)
352
+ - `<defs>`: arrow markers, gradients, filters, clip paths
353
+ - Text: minimum 12px, prefer 13-14px labels, 11px sub-labels, 16-18px titles
354
+ - All arrows: `<marker>` with `markerEnd`, sized `markerWidth="10" markerHeight="7"`
355
+ - Drop shadows: `<feDropShadow>` in `<filter>`, apply sparingly (key nodes only)
356
+ - Curved paths: use `M x1,y1 C cx1,cy1 cx2,cy2 x2,y2` cubic bezier for loops/feedback arrows
357
+ - Clip content: use `<clipPath>` if text might overflow a node box
358
+
359
+ ## SVG Generation & Error Prevention
360
+
361
+ **MANDATORY: Python List Method** (ALWAYS use this):
362
+ ```python
363
+ python3 << 'EOF'
364
+ lines = []
365
+ lines.append('<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 960 700">')
366
+ lines.append(' <defs>')
367
+ # ... each line separately
368
+ lines.append('</svg>')
369
+
370
+ with open('/path/to/output.svg', 'w') as f:
371
+ f.write('\n'.join(lines))
372
+ print("SVG generated successfully")
373
+ EOF
374
+ ```
375
+
376
+ **Why mandatory**: Prevents character truncation, typos, and syntax errors. Each line is independent and easy to verify.
377
+
378
+ **Pre-Tool-Call Checklist** (CRITICAL - use EVERY time):
379
+ 1. ✅ Can I write out the COMPLETE command/content right now?
380
+ 2. ✅ Do I have ALL required parameters ready?
381
+ 3. ✅ Have I checked for syntax errors in my prepared content?
382
+
383
+ **If ANY answer is NO**: STOP. Do NOT call the tool. Prepare the content first.
384
+
385
+ **Error Recovery Protocol**:
386
+ - **First error**: Analyze root cause, apply targeted fix
387
+ - **Second error**: Switch method entirely (Python list → chunked generation)
388
+ - **Third error**: STOP and report to user - do NOT loop endlessly
389
+ - **Never**: Retry the same failing command or call tools with empty parameters
390
+
391
+ **Validation** (run after generation):
392
+ ```bash
393
+ python3 -c "import xml.etree.ElementTree as ET; ET.parse('file.svg')" && echo "✓ Valid XML"
394
+ # Or use cairosvg as a render-time check:
395
+ python3 -c "import cairosvg; cairosvg.svg2png(url='file.svg', write_to='/tmp/test.png')" && echo "✓ Renders" && rm /tmp/test.png
396
+ ```
397
+
398
+ **If using `generate-from-template.py`**:
399
+ - Prefer `source` / `target` node ids in arrow JSON so the generator can snap to node edges
400
+ - Keep `x1,y1,x2,y2` as hints or fallback coordinates, not the main routing primitive
401
+ - Let the generator choose orthogonal routes; avoid hardcoding center-to-center straight lines unless the path is guaranteed clear
402
+
403
+ **Common Syntax Errors to Avoid**:
404
+ - ❌ `yt-anchor` → ✅ `y="60" text-anchor="middle"`
405
+ - ❌ `x="390` (missing y) → ✅ `x="390" y="250"`
406
+ - ❌ `fill=#fff` → ✅ `fill="#ffffff"`
407
+ - ❌ `marker-end=` → ✅ `marker-end="url(#arrow)"`
408
+ - ❌ `L 29450` → ✅ `L 290,220`
409
+ - ❌ Missing `</svg>` at end
410
+
411
+ ## Output
412
+
413
+ - **Default**: `./[derived-name].svg` and `./[derived-name].png` in current directory
414
+ - **Custom**: user specifies path with `--output /path/` or `输出到 /path/`
415
+ - **PNG export**: see **SVG → PNG Conversion** below
416
+
417
+ ## SVG → PNG Conversion
418
+
419
+ ### Method Comparison
420
+
421
+ | Tool | Install | Render Quality | Notes |
422
+ |------|---------|----------------|-------|
423
+ | `rsvg-convert` | System (often preinstalled) | ⚠️ Fair | Drops some CSS styles and `<foreignObject>` elements — missing borders/text on complex SVGs |
424
+ | **`cairosvg` (recommended)** | `pip install cairosvg` | ✅ Good | Solid CSS support; clearly better than rsvg-convert |
425
+ | `puppeteer` (headless Chrome) | `npm install puppeteer` | ✅✅ Best | Real browser engine; 100% fidelity but heavy (Node + Chromium) |
426
+
427
+ ### Recommended: cairosvg (Python one-liner)
428
+
429
+ ```bash
430
+ # Single file (2x resolution for retina/docs)
431
+ python3 -c "import cairosvg; cairosvg.svg2png(url='input.svg', write_to='output.png', scale=2)"
432
+
433
+ # Batch convert all SVGs in a directory
434
+ python3 -c "
435
+ import cairosvg, os, glob
436
+ d = 'docs/00-core'
437
+ for svg in sorted(glob.glob(os.path.join(d, '*.svg'))):
438
+ png = svg.replace('.svg', '.png')
439
+ cairosvg.svg2png(url=svg, write_to=png, scale=2)
440
+ print(f'Done: {os.path.basename(svg)} -> {os.path.basename(png)}')
441
+ "
442
+ ```
443
+
444
+ > `scale=2` produces 2x resolution PNG, ideal for high-DPI screens and embedded docs.
445
+
446
+ ### Fallback: rsvg-convert (simple but may drop styles)
447
+
448
+ ```bash
449
+ # Single file
450
+ rsvg-convert -w 1920 file.svg -o file.png
451
+
452
+ # Batch (not recommended — complex SVGs may lose elements)
453
+ for f in docs/00-core/*.svg; do rsvg-convert -o "${f%.svg}.png" "$f"; done
454
+
455
+ # 2x resolution
456
+ for f in docs/00-core/*.svg; do rsvg-convert -z 2 -o "${f%.svg}.png" "$f"; done
457
+ ```
458
+
459
+ ### Highest Fidelity: puppeteer (headless Chrome)
460
+
461
+ ```bash
462
+ npm install puppeteer # auto-downloads Chromium
463
+ node svg2png.js [directory]
464
+ ```
465
+
466
+ <details>
467
+ <summary>svg2png.js — full puppeteer script</summary>
468
+
469
+ ```javascript
470
+ const puppeteer = require('puppeteer');
471
+ const fs = require('fs');
472
+ const path = require('path');
473
+
474
+ (async () => {
475
+ const dir = process.argv[2] || '.';
476
+ const svgFiles = fs.readdirSync(dir).filter(f => f.endsWith('.svg'));
477
+
478
+ const browser = await puppeteer.launch({
479
+ headless: 'new',
480
+ args: ['--no-sandbox', '--disable-setuid-sandbox']
481
+ });
482
+
483
+ for (const file of svgFiles) {
484
+ const svgPath = path.resolve(dir, file);
485
+ const pngPath = svgPath.replace(/\.svg$/, '.png');
486
+ const svgContent = fs.readFileSync(svgPath, 'utf-8');
487
+
488
+ const wMatch = svgContent.match(/width="(\d+)/);
489
+ const hMatch = svgContent.match(/height="(\d+)/);
490
+ const vbMatch = svgContent.match(/viewBox="[^"]*\s(\d+)\s(\d+)"/);
491
+
492
+ let width = wMatch ? parseInt(wMatch[1]) : (vbMatch ? parseInt(vbMatch[1]) : 1200);
493
+ let height = hMatch ? parseInt(hMatch[1]) : (vbMatch ? parseInt(vbMatch[2]) : 800);
494
+
495
+ const scale = 2;
496
+ const page = await browser.newPage();
497
+ await page.setViewport({ width, height, deviceScaleFactor: scale });
498
+
499
+ const html = `<!DOCTYPE html>
500
+ <html><head><style>
501
+ body { margin: 0; padding: 0; background: transparent; }
502
+ img { display: block; }
503
+ </style></head>
504
+ <body>
505
+ <img src="data:image/svg+xml;base64,${Buffer.from(svgContent).toString('base64')}" width="${width}" height="${height}" />
506
+ </body></html>`;
507
+
508
+ await page.setContent(html, { waitUntil: 'networkidle0' });
509
+ await page.screenshot({ path: pngPath, type: 'png', omitBackground: true });
510
+ await page.close();
511
+
512
+ console.log(`Done: ${file} -> ${path.basename(pngPath)} (${width}x${height} @${scale}x)`);
513
+ }
514
+
515
+ await browser.close();
516
+ })();
517
+ ```
518
+
519
+ </details>
520
+
521
+ ### Gotchas (lessons learned)
522
+
523
+ - `rsvg-convert` renders SVGs containing `<foreignObject>`, CSS `filter`, or complex `<style>` blocks **incompletely** — missing borders / missing text are the typical symptoms
524
+ - `cairosvg` (built on Cairo) has much better CSS support than rsvg and is sufficient for most cases
525
+ - If the SVG was generated by a browser (D3.js, Mermaid, etc.), only headless Chrome (puppeteer) renders it 100% faithfully
526
+
527
+ ### Picking a Method
528
+
529
+ 1. **Default** → `cairosvg` (pip install once, one-line conversion, good fidelity)
530
+ 2. **No Python available** → `rsvg-convert` (acceptable for simple flat-color diagrams)
531
+ 3. **Browser-generated SVG or pixel-perfect required** → `puppeteer`
532
+
533
+ ## Styles
534
+
535
+ | # | Name | Background | Best For |
536
+ |---|------|-----------|----------|
537
+ | 1 | **Flat Icon** (default) | White | Blogs, docs, presentations |
538
+ | 2 | **Dark Terminal** | `#0f0f1a` | GitHub, dev articles |
539
+ | 3 | **Blueprint** | `#0a1628` | Architecture docs |
540
+ | 4 | **Notion Clean** | White, minimal | Notionnce |
541
+ | 5 | **Glassmorphism** | Dark gradient | Product sites, keynotes |
542
+ | 6 | **Claude Official** | Warm cream `#f8f6f3` | Anthropic-style diagrams |
543
+ | 7 | **OpenAI Official** | Pure white `#ffffff` | OpenAI-style diagrams |
544
+
545
+ Load `references/style-N.md` for exact color tokens and SVG patterns.
546
+
547
+ ## Style Selection
548
+
549
+ **Default**: Style 1 (Flat Icon) for most diagrams. Load `references/style-diagram-matrix.md` for detailed style-to-diagram-type recommendations.
550
+
551
+ These patterns appear frequently — internalize them:
552
+
553
+ **RAG Pipeline**: Query → Embed → VectorSearch → Retrieve → Augment → LLM → Response
554
+ **Agentic RAG**: adds Agent loop with Tool use between Query and LLM
555
+ **Agentic Search**: Query → Planner → [Search Tool / Calculator / Code] → Synthesizer → Response
556
+ **Mem0 / Memory Layer**: Input → Memory Manager → [Write: VectorDB + GraphDB] / [Read: Retrieve+Rank] → Context
557
+ **Agent Memory Types**: Sensory (raw input) → Working (context window) → Episodic (past interactions) → Semantic (facts) → Procedural (skills)
558
+ **Multi-Agent**: Orchestrator → [SubAgent A / SubAgent B / SubAgent C] → Aggregator → Output
559
+ **Tool Call Flow**: LLM → Tool Selector → Tool Execution → Result Parser → LLM (loop)
@@ -0,0 +1,4 @@
1
+ interface:
2
+ display_name: "Fireworks Tech Graph"
3
+ short_description: "Generate polished SVG and PNG technical diagrams"
4
+ default_prompt: "Turn the user's system or workflow description into a polished SVG diagram and export a PNG."