@haposoft/cafekit 0.7.22 → 0.7.24

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 (65) hide show
  1. package/README.md +81 -862
  2. package/bin/install.js +4 -3
  3. package/package.json +2 -3
  4. package/src/claude/agents/code-auditor.md +25 -1
  5. package/src/claude/agents/spec-maker.md +17 -2
  6. package/src/claude/agents/test-runner.md +22 -3
  7. package/src/claude/hooks/spec-state.cjs +4 -4
  8. package/src/claude/migration-manifest.json +1 -1
  9. package/src/claude/rules/state-sync.md +7 -5
  10. package/src/claude/skills/code-review/references/spec-compliance-review.md +8 -1
  11. package/src/claude/skills/develop/SKILL.md +26 -4
  12. package/src/claude/skills/develop/references/quality-gate.md +23 -13
  13. package/src/claude/skills/generate-graph/LICENSE +21 -0
  14. package/src/claude/skills/generate-graph/README.md +523 -0
  15. package/src/claude/skills/generate-graph/SKILL.md +427 -0
  16. package/src/claude/skills/generate-graph/agentloop-core.svg +101 -0
  17. package/src/claude/skills/generate-graph/agents/openai.yaml +4 -0
  18. package/src/claude/skills/generate-graph/assets/samples/sample-style1-flat.png +0 -0
  19. package/src/claude/skills/generate-graph/assets/samples/sample-style2-dark.png +0 -0
  20. package/src/claude/skills/generate-graph/assets/samples/sample-style3-blueprint.png +0 -0
  21. package/src/claude/skills/generate-graph/assets/samples/sample-style4-notion.png +0 -0
  22. package/src/claude/skills/generate-graph/assets/samples/sample-style5-glass.png +0 -0
  23. package/src/claude/skills/generate-graph/assets/samples/sample-style6-claude.png +0 -0
  24. package/src/claude/skills/generate-graph/assets/samples/sample-style7-openai.png +0 -0
  25. package/src/claude/skills/generate-graph/fixtures/agent-memory-types-style4.json +181 -0
  26. package/src/claude/skills/generate-graph/fixtures/api-flow-style7.json +40 -0
  27. package/src/claude/skills/generate-graph/fixtures/mem0-style1.json +297 -0
  28. package/src/claude/skills/generate-graph/fixtures/microservices-style3.json +64 -0
  29. package/src/claude/skills/generate-graph/fixtures/multi-agent-style5.json +45 -0
  30. package/src/claude/skills/generate-graph/fixtures/system-architecture-style6.json +48 -0
  31. package/src/claude/skills/generate-graph/fixtures/tool-call-style2.json +182 -0
  32. package/src/claude/skills/generate-graph/package.json +42 -0
  33. package/src/claude/skills/generate-graph/references/icons.md +281 -0
  34. package/src/claude/skills/generate-graph/references/style-1-flat-icon.md +108 -0
  35. package/src/claude/skills/generate-graph/references/style-2-dark-terminal.md +107 -0
  36. package/src/claude/skills/generate-graph/references/style-3-blueprint.md +113 -0
  37. package/src/claude/skills/generate-graph/references/style-4-notion-clean.md +94 -0
  38. package/src/claude/skills/generate-graph/references/style-5-glassmorphism.md +125 -0
  39. package/src/claude/skills/generate-graph/references/style-6-claude-official.md +209 -0
  40. package/src/claude/skills/generate-graph/references/style-7-openai.md +215 -0
  41. package/src/claude/skills/generate-graph/references/style-diagram-matrix.md +135 -0
  42. package/src/claude/skills/generate-graph/references/svg-layout-best-practices.md +100 -0
  43. package/src/claude/skills/generate-graph/scripts/generate-diagram.sh +157 -0
  44. package/src/claude/skills/generate-graph/scripts/generate-from-template.py +1556 -0
  45. package/src/claude/skills/generate-graph/scripts/test-all-styles.sh +135 -0
  46. package/src/claude/skills/generate-graph/scripts/validate-svg.sh +292 -0
  47. package/src/claude/skills/generate-graph/templates/agent-architecture.svg +28 -0
  48. package/src/claude/skills/generate-graph/templates/architecture.svg +23 -0
  49. package/src/claude/skills/generate-graph/templates/comparison-matrix.svg +14 -0
  50. package/src/claude/skills/generate-graph/templates/data-flow.svg +28 -0
  51. package/src/claude/skills/generate-graph/templates/er-diagram.svg +21 -0
  52. package/src/claude/skills/generate-graph/templates/flowchart.svg +21 -0
  53. package/src/claude/skills/generate-graph/templates/sequence.svg +20 -0
  54. package/src/claude/skills/generate-graph/templates/state-machine.svg +20 -0
  55. package/src/claude/skills/generate-graph/templates/timeline.svg +19 -0
  56. package/src/claude/skills/generate-graph/templates/use-case.svg +21 -0
  57. package/src/claude/skills/specs/SKILL.md +38 -7
  58. package/src/claude/skills/specs/references/codebase-analysis.md +26 -9
  59. package/src/claude/skills/specs/references/research-strategy.md +3 -3
  60. package/src/claude/skills/specs/references/review.md +1 -1
  61. package/src/claude/skills/specs/rules/tasks-generation.md +17 -0
  62. package/src/claude/skills/specs/templates/design.md +13 -0
  63. package/src/claude/skills/specs/templates/init.json +4 -1
  64. package/src/claude/skills/specs/templates/requirements.md +21 -8
  65. package/src/claude/skills/specs/templates/task.md +16 -3
@@ -0,0 +1,427 @@
1
+ ---
2
+ name: hapo:generate-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: "generate diagram" "draw diagram" "visualize" or any
7
+ system/flow description the user wants illustrated.
8
+ ---
9
+
10
+ # Generate Graph
11
+
12
+ Generate production-quality SVG technical diagrams exported as PNG via `rsvg-convert`.
13
+
14
+ ## CafeKit Integration
15
+
16
+ This skill is bundled with CafeKit and is expected to live under:
17
+
18
+ ```bash
19
+ .claude/skills/generate-graph
20
+ ```
21
+
22
+ Runtime prerequisites:
23
+
24
+ ```bash
25
+ python3
26
+ rsvg-convert
27
+ ```
28
+
29
+ `rsvg-convert` is recommended for syntax validation and PNG export. If it is unavailable, you can still generate SVG output and skip PNG export.
30
+
31
+ ## Helper Scripts (Recommended)
32
+
33
+ Four helper scripts in `scripts/` directory provide stable SVG generation and validation:
34
+
35
+ ### 1. `generate-diagram.sh` - Validate SVG + export PNG
36
+ ```bash
37
+ ./scripts/generate-diagram.sh -t architecture -s 1 -o ./output/arch.svg
38
+ ```
39
+ - Validates an existing SVG file
40
+ - Exports PNG after validation
41
+ - Example: `./scripts/generate-diagram.sh -t architecture -s 1 -o ./output/arch.svg`
42
+
43
+ ### 2. `generate-from-template.py` - Create starter SVG from template
44
+ ```bash
45
+ python3 ./scripts/generate-from-template.py architecture ./output/arch.svg '{"title":"My Diagram","nodes":[],"arrows":[]}'
46
+ ```
47
+ - Loads a built-in SVG template
48
+ - Renders nodes, arrows, and legend entries from JSON input
49
+ - Escapes text content to keep output XML-valid
50
+
51
+ ### 3. `validate-svg.sh` - Validate SVG syntax
52
+ ```bash
53
+ ./scripts/validate-svg.sh <svg-file>
54
+ ```
55
+ - Checks XML syntax
56
+ - Verifies tag balance
57
+ - Validates marker references
58
+ - Checks attribute completeness
59
+ - Validates path data
60
+
61
+ ### 4. `test-all-styles.sh` - Batch test all styles
62
+ ```bash
63
+ ./scripts/test-all-styles.sh
64
+ ```
65
+ - Tests multiple diagram sizes
66
+ - Validates all generated SVGs
67
+ - Generates test report
68
+
69
+ **When to use scripts:**
70
+ - Use scripts when generating complex SVGs to avoid syntax errors
71
+ - Scripts provide automatic validation and error reporting
72
+ - Recommended for production diagrams
73
+
74
+ **When to generate SVG directly:**
75
+ - Simple diagrams with few elements
76
+ - Quick prototypes
77
+ - When you need full control over SVG structure
78
+
79
+ ## Workflow (Always Follow This Order)
80
+
81
+ 1. **Classify** the diagram type (see Diagram Types below)
82
+ 2. **Extract structure** — identify layers, nodes, edges, flows, and semantic groups from user description
83
+ 3. **Plan layout** — apply the layout rules for the diagram type
84
+ 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
85
+ 5. **Map nodes to shapes** — use Shape Vocabulary below
86
+ 6. **Check icon needs** — load `references/icons.md` for known products
87
+ 7. **Write SVG** with adaptive strategy (see SVG Generation Strategy below)
88
+ 8. **Validate**: Run `rsvg-convert file.svg -o /dev/null 2>&1` to check syntax
89
+ 9. **Export PNG**: `rsvg-convert -w 1920 file.svg -o file.png`
90
+ 10. **Report** the generated file paths
91
+
92
+ ## Diagram Types & Layout Rules
93
+
94
+ ### Architecture Diagram
95
+ Nodes = services/components. Group into **horizontal layers** (top→bottom or left→right).
96
+ - Typical layers: Client → Gateway/LB → Services → Data/Storage
97
+ - Use `<rect>` dashed containers to group related services in the same layer
98
+ - Arrow direction follows data/request flow
99
+ - ViewBox: `0 0 960 600` standard, `0 0 960 800` for tall stacks
100
+
101
+ ### Data Flow Diagram
102
+ Emphasizes **what data moves where**. Focus on data transformation.
103
+ - Label every arrow with the data type (e.g., "embeddings", "query", "context")
104
+ - Use wider arrows (`stroke-width: 2.5`) for primary data paths
105
+ - Dashed arrows for control/trigger flows
106
+ - Color arrows by data category (not just Agent/RAG — use semantics)
107
+
108
+ ### Flowchart / Process Flow
109
+ Sequential decision/process steps.
110
+ - Top-to-bottom preferred; left-to-right for wide flows
111
+ - Diamond shapes for decisions, rounded rects for processes, parallelograms for I/O
112
+ - Keep node labels short (≤3 words); put detail in sub-labels
113
+ - Align nodes on a grid: x positions snap to 120px intervals, y to 80px
114
+
115
+ ### Agent Architecture Diagram
116
+ Shows how an AI agent reasons, uses tools, and manages memory.
117
+ Key conceptual layers to always consider:
118
+ - **Input layer**: User, query, trigger
119
+ - **Agent core**: LLM, reasoning loop, planner
120
+ - **Memory layer**: Short-term (context window), Long-term (vector/graph DB), Episodic
121
+ - **Tool layer**: Tool calls, APIs, search, code execution
122
+ - **Output layer**: Response, action, side-effects
123
+ Use cyclic arrows (loop arcs) to show iterative reasoning. Separate memory types visually.
124
+
125
+ ### Memory Architecture Diagram (Mem0, MemGPT-style)
126
+ Specialized agent diagram focused on memory operations.
127
+ - Show memory **write path** and **read path** separately (different arrow colors)
128
+ - Memory tiers: Working Memory → Short-term → Long-term → External Store
129
+ - Label memory operations: `store()`, `retrieve()`, `forget()`, `consolidate()`
130
+ - Use stacked rects or layered cylinders for storage tiers
131
+
132
+ ### Sequence Diagram
133
+ Time-ordered message exchanges between participants.
134
+ - Participants as vertical **lifelines** (top labels + vertical dashed lines)
135
+ - Messages as horizontal arrows between lifelines, top-to-bottom time order
136
+ - Activation boxes (thin filled rects on lifeline) show active processing
137
+ - Group with `<rect>` loop/alt frames with label in top-left corner
138
+ - ViewBox height = 80 + (num_messages × 50)
139
+
140
+ ### Comparison / Feature Matrix
141
+ Side-by-side comparison of approaches, systems, or components.
142
+ - Column headers = systems, row headers = attributes
143
+ - Row height: 40px; column width: min 120px; header row height: 50px
144
+ - Checked cell: tinted background (e.g. `#dcfce7`) + `✓` checkmark; unsupported: `#f9fafb` fill
145
+ - Alternating row fills (`#f9fafb` / `#ffffff`) for readability
146
+ - Max readable columns: 5; beyond that, split into two diagrams
147
+
148
+ ### Timeline / Gantt
149
+ Horizontal time axis showing durations, phases, and milestones.
150
+ - X-axis = time (weeks/months/quarters); Y-axis = items/tasks/phases
151
+ - Bars: rounded rects, colored by category, labeled inside or beside
152
+ - Milestone markers: diamond or filled circle at specific x position with label above
153
+ - ViewBox: `0 0 960 400` typical; wider for many time periods: `0 0 1200 400`
154
+
155
+ ### Mind Map / Concept Map
156
+ Radial layout from central concept.
157
+ - Central node at `cx=480, cy=280`
158
+ - First-level branches: evenly distributed around center (360/N degrees)
159
+ - Second-level branches: branch off first-level at 30-45° offset
160
+ - Use curved `<path>` with cubic bezier for branches, not straight lines
161
+
162
+ ### Class Diagram (UML)
163
+ Static structure showing classes, attributes, methods, and relationships.
164
+ - **Class box**: 3-compartment rect (name / attributes / methods), min width 160px
165
+ - Top compartment: class name, bold, centered (abstract = *italic*)
166
+ - Middle: attributes with visibility (`+` public, `-` private, `#` protected)
167
+ - Bottom: method signatures, same visibility notation
168
+ - **Relationships**:
169
+ - Inheritance (extends): solid line + hollow triangle arrowhead, child → parent
170
+ - Implementation (interface): dashed line + hollow triangle, class → interface
171
+ - Association: solid line + open arrowhead, label with multiplicity (1, 0..*, 1..*)
172
+ - Aggregation: solid line + hollow diamond on container side
173
+ - Composition: solid line + filled diamond on container side
174
+ - Dependency: dashed line + open arrowhead
175
+ - **Interface**: `<<interface>>` stereotype above name, or circle/lollipop notation
176
+ - **Enum**: compartment rect with `<<enumeration>>` stereotype, values in bottom
177
+ - Layout: parent classes top, children below; interfaces to the left/right of implementors
178
+ - ViewBox: `0 0 960 600` standard; `0 0 960 800` for deep hierarchies
179
+
180
+ ### Use Case Diagram (UML)
181
+ System functionality from user perspective.
182
+ - **Actor**: stick figure (circle head + body line) placed outside system boundary
183
+ - Label below figure, 13-14px
184
+ - Primary actors on left, secondary/supporting on right
185
+ - **Use case**: ellipse with label centered inside, min 140×60px
186
+ - Keep names verb phrases: "Create Order", "Process Payment"
187
+ - **System boundary**: large rect with dashed border + system name in top-left
188
+ - **Relationships**:
189
+ - Include: dashed arrow `<<include>>` from base to included use case
190
+ - Extend: dashed arrow `<<extend>>` from extension to base use case
191
+ - Generalization: solid line + hollow triangle (specialized → general)
192
+ - Layout: system boundary centered, actors outside, use cases inside
193
+ - ViewBox: `0 0 960 600` standard
194
+
195
+ ### State Machine Diagram (UML)
196
+ Lifecycle states and transitions of an entity.
197
+ - **State**: rounded rect with state name, min 120×50px
198
+ - Internal activities: small text `entry/ action`, `exit/ action`, `do/ activity`
199
+ - **Initial state**: filled black circle (r=8), one outgoing arrow
200
+ - **Final state**: filled circle (r=8) inside hollow circle (r=12)
201
+ - **Choice**: small hollow diamond, guard labels on outgoing arrows `[condition]`
202
+ - **Transition**: arrow with optional label `event [guard] / action`
203
+ - Guard conditions in square brackets
204
+ - Actions after `/`
205
+ - **Composite/nested state**: larger rect containing sub-states, with name tab
206
+ - **Fork/join**: thick horizontal or vertical black bar (synchronization)
207
+ - Layout: initial state top-left, final state bottom-right, flow top-to-bottom
208
+ - ViewBox: `0 0 960 600` standard
209
+
210
+ ### ER Diagram (Entity-Relationship)
211
+ Database schema and data relationships.
212
+ - **Entity**: rect with entity name in header (bold), attributes below
213
+ - Primary key attribute: underlined
214
+ - Foreign key: italic or marked with (FK)
215
+ - Min width: 160px; attribute font-size: 12px
216
+ - **Relationship**: diamond shape on connecting line
217
+ - Label inside diamond: "has", "belongs to", "enrolls in"
218
+ - Cardinality labels near entity: `1`, `N`, `0..1`, `0..*`, `1..*`
219
+ - **Weak entity**: double-bordered rect with double diamond relationship
220
+ - **Associative entity**: diamond + rect hybrid (rect with diamond inside)
221
+ - Line style: solid for identifying relationships, dashed for non-identifying
222
+ - Layout: entities in 2-3 rows, relationships between related entities
223
+ - ViewBox: `0 0 960 600` standard; wider `0 0 1200 600` for many entities
224
+
225
+ ### Network Topology
226
+ Physical or logical network infrastructure.
227
+ - **Devices**: icon-like rects or rounded rects
228
+ - Router: circle with cross arrows
229
+ - Switch: rect with arrow grid
230
+ - Server: stacked rect (rack icon)
231
+ - Firewall: brick-pattern rect or shield shape
232
+ - Load Balancer: horizontal split rect with arrows
233
+ - Cloud: cloud path (overlapping arcs)
234
+ - **Connections**: lines between device centers
235
+ - Ethernet/wired: solid line, label bandwidth
236
+ - Wireless: dashed line with WiFi symbol
237
+ - VPN: dashed line with lock icon
238
+ - **Subnets/Zones**: dashed rect containers with zone label (DMZ, Internal, External)
239
+ - **Labels**: device hostname + IP below, 12-13px
240
+ - Layout: tiered top-to-bottom (Internet → Edge → Core → Access → Endpoints)
241
+ - ViewBox: `0 0 960 600` standard
242
+
243
+ ## UML Coverage Map
244
+
245
+ Full mapping of UML 14 diagram types to supported diagram types:
246
+
247
+ | UML Diagram | Supported As | Notes |
248
+ |-------------|-------------|-------|
249
+ | Class | Class Diagram | Full UML notation |
250
+ | Component | Architecture Diagram | Use colored fills per component type |
251
+ | Deployment | Architecture Diagram | Add node/instance labels |
252
+ | Package | Architecture Diagram | Use dashed grouping containers |
253
+ | Composite Structure | Architecture Diagram | Nested rects within components |
254
+ | Object | Class Diagram | Instance boxes with underlined name |
255
+ | Use Case | Use Case Diagram | Full actor/ellipse/relationship |
256
+ | Activity | Flowchart / Process Flow | Add fork/join bars |
257
+ | State Machine | State Machine Diagram | Full UML notation |
258
+ | Sequence | Sequence Diagram | Add alt/opt/loop frames |
259
+ | Communication | — | Approximate with Sequence (swap axes) |
260
+ | Timing | Timeline | Adapt time axis |
261
+ | Interaction Overview | Flowchart | Combine activity + sequence fragments |
262
+ | ER Diagram | ER Diagram | Chen/Crow's foot notation |
263
+
264
+ ## Shape Vocabulary
265
+
266
+ Map semantic concepts to consistent shapes across all diagram types:
267
+
268
+ | Concept | Shape | Notes |
269
+ |---------|-------|-------|
270
+ | User / Human | Circle + body path | Stick figure or avatar |
271
+ | LLM / Model | Rounded rect with brain/spark icon or gradient fill | Use accent color |
272
+ | Agent / Orchestrator | Hexagon or rounded rect with double border | Signals "active controller" |
273
+ | Memory (short-term) | Rounded rect, dashed border | Ephemeral = dashed |
274
+ | Memory (long-term) | Cylinder (database shape) | Persistent = solid cylinder |
275
+ | Vector Store | Cylinder with grid lines inside | Add 3 horizontal lines |
276
+ | Graph DB | Circle cluster (3 overlapping circles) | |
277
+ | Tool / Function | Gear-like rect or rect with wrench icon | |
278
+ | API / Gateway | Hexagon (single border) | |
279
+ | Queue / Stream | Horizontal tube (pipe shape) | |
280
+ | File / Document | Folded-corner rect | |
281
+ | Browser / UI | Rect with 3-dot titlebar | |
282
+ | Decision | Diamond | Flowcharts only |
283
+ | Process / Step | Rounded rect | Standard box |
284
+ | External Service | Rect with cloud icon or dashed border | |
285
+ | Data / Artifact | Parallelogram | I/O in flowcharts |
286
+
287
+ ## Arrow Semantics
288
+
289
+ Always assign arrow meaning, not just color:
290
+
291
+ | Flow Type | Color | Stroke | Dash | Meaning |
292
+ |-----------|-------|--------|------|---------|
293
+ | Primary data flow | blue `#2563eb` | 2px solid | none | Main request/response path |
294
+ | Control / trigger | orange `#ea580c` | 1.5px solid | none | One system triggering another |
295
+ | Memory read | green `#059669` | 1.5px solid | none | Retrieval from store |
296
+ | Memory write | green `#059669` | 1.5px | `5,3` | Write/store operation |
297
+ | Async / event | gray `#6b7280` | 1.5px | `4,2` | Non-blocking, event-driven |
298
+ | Embedding / transform | purple `#7c3aed` | 1px solid | none | Data transformation |
299
+ | Feedback / loop | purple `#7c3aed` | 1.5px curved | none | Iterative reasoning loop |
300
+
301
+ Always include a **legend** when 2+ arrow types are used.
302
+
303
+ ## Layout Rules & Validation
304
+
305
+ **Spacing**:
306
+ - Same-layer nodes: 80px horizontal, 120px vertical between layers
307
+ - Canvas margins: 40px minimum, 60px between node edges
308
+ - Snap to 8px grid: horizontal 120px intervals, vertical 120px intervals
309
+
310
+ **Arrow Labels** (CRITICAL):
311
+ - MUST have background rect: `<rect fill="canvas_bg" opacity="0.95"/>` with 4px horizontal, 2px vertical padding
312
+ - Place mid-arrow, ≤3 words, stagger by 15-20px when multiple arrows converge
313
+ - Maintain 10px safety distance from nodes
314
+
315
+ **Arrow Routing**:
316
+ - Prefer orthogonal (L-shaped) paths to minimize crossings
317
+ - Anchor arrows on component edges, not geometric centers
318
+ - Route around dense node clusters, use different y-offsets for parallel arrows
319
+ - Jump-over arcs (5px radius) for unavoidable crossings
320
+
321
+ **Line Overlap Prevention** (CRITICAL - most common bug on Codex):
322
+ When two arrows must cross each other, ALWAYS use jump-over arcs to prevent visual overlap:
323
+ - Crossing horizontal arrows: add a small semicircle arc (radius 5px, stroke same color as arrow, fill none) that "jumps over" the other line
324
+ - SVG pattern for jump-over: use a white/matching-background arc on the lower layer, then draw the upper arc on top
325
+ - Multiple crossings: stagger arc radii (5px, 7px, 9px) so arcs don't overlap each other
326
+ - Never let two arrows' straight-line segments cross without a jump-over arc
327
+
328
+ **Validation Checklist** (run before finalizing):
329
+ 1. **Arrow-Component Collision**: Arrows MUST NOT pass through component interiors (route around with orthogonal paths)
330
+ 2. **Text Overflow**: All text MUST fit with 8px padding (estimate: `text.length × 7px ≤ shape_width - 16px`)
331
+ 3. **Arrow-Text Alignment**: Arrow endpoints MUST connect to shape edges (not floating); all arrow labels MUST have background rects
332
+ 4. **Container Discipline**: Prefer arrows entering and leaving section containers through open gaps between components, not through inner component bodies
333
+
334
+ ## SVG Technical Rules
335
+
336
+ - ViewBox: `0 0 960 600` default; `0 0 960 800` tall; `0 0 1200 600` wide
337
+ - Fonts: embed via `<style>font-family: ...</style>` — no external `@import` (breaks rsvg-convert)
338
+ - `<defs>`: arrow markers, gradients, filters, clip paths
339
+ - Text: minimum 12px, prefer 13-14px labels, 11px sub-labels, 16-18px titles
340
+ - All arrows: `<marker>` with `markerEnd`, sized `markerWidth="10" markerHeight="7"`
341
+ - Drop shadows: `<feDropShadow>` in `<filter>`, apply sparingly (key nodes only)
342
+ - Curved paths: use `M x1,y1 C cx1,cy1 cx2,cy2 x2,y2` cubic bezier for loops/feedback arrows
343
+ - Clip content: use `<clipPath>` if text might overflow a node box
344
+
345
+ ## SVG Generation & Error Prevention
346
+
347
+ **MANDATORY: Python List Method** (ALWAYS use this):
348
+ ```python
349
+ python3 << 'EOF'
350
+ lines = []
351
+ lines.append('<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 960 700">')
352
+ lines.append(' <defs>')
353
+ # ... each line separately
354
+ lines.append('</svg>')
355
+
356
+ with open('/path/to/output.svg', 'w') as f:
357
+ f.write('\n'.join(lines))
358
+ print("SVG generated successfully")
359
+ EOF
360
+ ```
361
+
362
+ **Why mandatory**: Prevents character truncation, typos, and syntax errors. Each line is independent and easy to verify.
363
+
364
+ **Pre-Tool-Call Checklist** (CRITICAL - use EVERY time):
365
+ 1. ✅ Can I write out the COMPLETE command/content right now?
366
+ 2. ✅ Do I have ALL required parameters ready?
367
+ 3. ✅ Have I checked for syntax errors in my prepared content?
368
+
369
+ **If ANY answer is NO**: STOP. Do NOT call the tool. Prepare the content first.
370
+
371
+ **Error Recovery Protocol**:
372
+ - **First error**: Analyze root cause, apply targeted fix
373
+ - **Second error**: Switch method entirely (Python list → chunked generation)
374
+ - **Third error**: STOP and report to user - do NOT loop endlessly
375
+ - **Never**: Retry the same failing command or call tools with empty parameters
376
+
377
+ **Validation** (run after generation):
378
+ ```bash
379
+ rsvg-convert file.svg -o /tmp/test.png 2>&1 && echo "✓ Valid" && rm /tmp/test.png
380
+ ```
381
+
382
+ **If using `generate-from-template.py`**:
383
+ - Prefer `source` / `target` node ids in arrow JSON so the generator can snap to node edges
384
+ - Keep `x1,y1,x2,y2` as hints or fallback coordinates, not the main routing primitive
385
+ - Let the generator choose orthogonal routes; avoid hardcoding center-to-center straight lines unless the path is guaranteed clear
386
+
387
+ **Common Syntax Errors to Avoid**:
388
+ - ❌ `yt-anchor` → ✅ `y="60" text-anchor="middle"`
389
+ - ❌ `x="390` (missing y) → ✅ `x="390" y="250"`
390
+ - ❌ `fill=#fff` → ✅ `fill="#ffffff"`
391
+ - ❌ `marker-end=` → ✅ `marker-end="url(#arrow)"`
392
+ - ❌ `L 29450` → ✅ `L 290,220`
393
+ - ❌ Missing `</svg>` at end
394
+
395
+ ## Output
396
+
397
+ - **Default**: `./[derived-name].svg` and `./[derived-name].png` in current directory
398
+ - **Custom**: user specifies path with `--output /path/` or `输出到 /path/`
399
+ - **PNG export**: `rsvg-convert -w 1920 file.svg -o file.png` (1920px = 2x retina)
400
+
401
+ ## Styles
402
+
403
+ | # | Name | Background | Best For |
404
+ |---|------|-----------|----------|
405
+ | 1 | **Flat Icon** (default) | White | Blogs, docs, presentations |
406
+ | 2 | **Dark Terminal** | `#0f0f1a` | GitHub, dev articles |
407
+ | 3 | **Blueprint** | `#0a1628` | Architecture docs |
408
+ | 4 | **Notion Clean** | White, minimal | Notionnce |
409
+ | 5 | **Glassmorphism** | Dark gradient | Product sites, keynotes |
410
+ | 6 | **Claude Official** | Warm cream `#f8f6f3` | Anthropic-style diagrams |
411
+ | 7 | **OpenAI Official** | Pure white `#ffffff` | OpenAI-style diagrams |
412
+
413
+ Load `references/style-N.md` for exact color tokens and SVG patterns.
414
+
415
+ ## Style Selection
416
+
417
+ **Default**: Style 1 (Flat Icon) for most diagrams. Load `references/style-diagram-matrix.md` for detailed style-to-diagram-type recommendations.
418
+
419
+ These patterns appear frequently — internalize them:
420
+
421
+ **RAG Pipeline**: Query → Embed → VectorSearch → Retrieve → Augment → LLM → Response
422
+ **Agentic RAG**: adds Agent loop with Tool use between Query and LLM
423
+ **Agentic Search**: Query → Planner → [Search Tool / Calculator / Code] → Synthesizer → Response
424
+ **Mem0 / Memory Layer**: Input → Memory Manager → [Write: VectorDB + GraphDB] / [Read: Retrieve+Rank] → Context
425
+ **Agent Memory Types**: Sensory (raw input) → Working (context window) → Episodic (past interactions) → Semantic (facts) → Procedural (skills)
426
+ **Multi-Agent**: Orchestrator → [SubAgent A / SubAgent B / SubAgent C] → Aggregator → Output
427
+ **Tool Call Flow**: LLM → Tool Selector → Tool Execution → Result Parser → LLM (loop)
@@ -0,0 +1,101 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 960 700">
2
+ <defs>
3
+ <marker id="arrowBlue" markerWidth="10" markerHeight="7" refX="9" refY="3.5" orient="auto">
4
+ <polygon points="0 0, 10 3.5, 0 7" fill="#2563eb"/>
5
+ </marker>
6
+ <marker id="arrowPurple" markerWidth="10" markerHeight="7" refX="9" refY="3.5" orient="auto">
7
+ <polygon points="0 0, 10 3.5, 0 7" fill="#7c3aed"/>
8
+ </marker>
9
+ <marker id="arrowGreen" markerWidth="10" markerHeight="7" refX="9" refY="3.5" orient="auto">
10
+ <polygon points="0 0, 10 3.5, 0 7" fill="#059669"/>
11
+ </marker>
12
+ <marker id="arrowOrange" markerWidth="10" markerHeight="7" refX="9" refY="3.5" orient="auto">
13
+ <polygon points="0 0, 10 3.5, 0 7" fill="#ea580c"/>
14
+ </marker>
15
+ </defs>
16
+ <style>
17
+ text { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
18
+ .title { font-size: 24px; font-weight: 700; fill: #1e293b; }
19
+ .node-label { font-size: 16px; font-weight: 600; fill: #1e293b; }
20
+ .sub-label { font-size: 13px; font-weight: 400; fill: #64748b; }
21
+ .arrow-label { font-size: 12px; font-weight: 400; fill: #475569; }
22
+ </style>
23
+ <rect width="960" height="700" fill="#ffffff"/>
24
+ <text x="480" y="50" text-anchor="middle" class="title">AgentLoop Core Architecture</text>
25
+
26
+ <!-- Input Layer -->
27
+ <circle cx="480" cy="120" r="35" fill="#dbeafe" stroke="#2563eb" stroke-width="2.5"/>
28
+ <text x="480" y="118" text-anchor="middle" class="node-label">User</text>
29
+ <text x="480" y="135" text-anchor="middle" class="sub-label">Input</text>
30
+
31
+ <!-- Agent Core -->
32
+ <rect x="360" y="200" width="240" height="100" rx="12" fill="#f3e8ff" stroke="#7c3aed" stroke-width="3"/>
33
+ <text x="480" y="235" text-anchor="middle" class="node-label">Agent Loop</text>
34
+ <text x="480" y="255" text-anchor="middle" class="sub-label">Reasoning Engine</text>
35
+ <text x="480" y="275" text-anchor="middle" class="sub-label">Plan → Act → Observe</text>
36
+
37
+ <!-- Memory Layer -->
38
+ <rect x="100" y="220" width="180" height="60" rx="8" fill="#dcfce7" stroke="#059669" stroke-width="2.5" stroke-dasharray="5,3"/>
39
+ <text x="190" y="245" text-anchor="middle" class="node-label">Short-term</text>
40
+ <text x="190" y="265" text-anchor="middle" class="sub-label">Context Window</text>
41
+
42
+ <ellipse cx="190" cy="400" rx="80" ry="50" fill="#dcfce7" stroke="#059669" stroke-width="2.5"/>
43
+ <text x="190" y="395" text-anchor="middle" class="node-label">Long-term</text>
44
+ <text x="190" y="415" text-anchor="middle" class="sub-label">Vector Store</text>
45
+
46
+ <!-- Tool Layer -->
47
+ <rect x="680" y="220" width="160" height="60" rx="8" fill="#fed7aa" stroke="#ea580c" stroke-width="2.5"/>
48
+ <text x="760" y="245" text-anchor="middle" class="node-label">Tools</text>
49
+ <text x="760" y="265" text-anchor="middle" class="sub-label">Functions</text>
50
+
51
+ <!-- Output Layer -->
52
+ <rect x="390" y="500" width="180" height="70" rx="8" fill="#dbeafe" stroke="#2563eb" stroke-width="2.5"/>
53
+ <text x="480" y="525" text-anchor="middle" class="node-label">Response</text>
54
+ <text x="480" y="545" text-anchor="middle" class="sub-label">Action / Output</text>
55
+
56
+ <!-- Arrows -->
57
+ <line x1="480" y1="155" x2="480" y2="200" stroke="#2563eb" stroke-width="2" marker-end="url(#arrowBlue)"/>
58
+ <rect x="455" y="168" width="50" height="18" fill="#ffffff" opacity="0.95"/>
59
+ <text x="480" y="180" text-anchor="middle" class="arrow-label">query</text>
60
+
61
+ <path d="M 360,250 L 280,250" stroke="#059669" stroke-width="2" marker-end="url(#arrowGreen)"/>
62
+ <rect x="295" y="237" width="50" height="18" fill="#ffffff" opacity="0.95"/>
63
+ <text x="320" y="249" text-anchor="middle" class="arrow-label">read</text>
64
+
65
+ <path d="M 280,250 L 360,250" stroke="#059669" stroke-width="2" stroke-dasharray="5,3" marker-end="url(#arrowGreen)"/>
66
+ <rect x="297" y="257" width="50" height="18" fill="#ffffff" opacity="0.95"/>
67
+ <text x="320" y="269" text-anchor="middle" class="arrow-label">write</text>
68
+
69
+ <path d="M 600,250 L 680,250" stroke="#ea580c" stroke-width="2" marker-end="url(#arrowOrange)"/>
70
+ <rect x="615" y="237" width="50" height="18" fill="#ffffff" opacity="0.95"/>
71
+ <text x="640" y="249" text-anchor="middle" class="arrow-label">call</text>
72
+
73
+ <path d="M 680,250 L 600,250" stroke="#ea580c" stroke-width="2" marker-end="url(#arrowOrange)"/>
74
+ <rect x="615" y="257" width="55" height="18" fill="#ffffff" opacity="0.95"/>
75
+ <text x="642" y="269" text-anchor="middle" class="arrow-label">result</text>
76
+
77
+ <line x1="480" y1="300" x2="480" y2="500" stroke="#2563eb" stroke-width="2" marker-end="url(#arrowBlue)"/>
78
+ <rect x="445" y="390" width="70" height="18" fill="#ffffff" opacity="0.95"/>
79
+ <text x="480" y="402" text-anchor="middle" class="arrow-label">generate</text>
80
+
81
+ <path d="M 240,380 Q 240,320 360,280" stroke="#059669" stroke-width="1.5" marker-end="url(#arrowGreen)"/>
82
+ <rect x="265" y="317" width="60" height="18" fill="#ffffff" opacity="0.95"/>
83
+ <text x="295" y="329" text-anchor="middle" class="arrow-label">retrieve</text>
84
+
85
+ <path d="M 420,300 Q 420,450 390,520" stroke="#7c3aed" stroke-width="2" marker-end="url(#arrowPurple)"/>
86
+ <rect x="365" y="400" width="60" height="18" fill="#ffffff" opacity="0.95"/>
87
+ <text x="395" y="412" text-anchor="middle" class="arrow-label">feedback</text>
88
+
89
+ <!-- Legend -->
90
+ <line x1="750" y1="90" x2="780" y2="90" stroke="#2563eb" stroke-width="2" marker-end="url(#arrowBlue)"/>
91
+ <text x="790" y="95" class="arrow-label">Data Flow</text>
92
+
93
+ <line x1="750" y1="115" x2="780" y2="115" stroke="#059669" stroke-width="2" marker-end="url(#arrowGreen)"/>
94
+ <text x="790" y="120" class="arrow-label">Memory</text>
95
+
96
+ <line x1="750" y1="140" x2="780" y2="140" stroke="#ea580c" stroke-width="2" marker-end="url(#arrowOrange)"/>
97
+ <text x="790" y="145" class="arrow-label">Tool Call</text>
98
+
99
+ <line x1="750" y1="165" x2="780" y2="165" stroke="#7c3aed" stroke-width="2" marker-end="url(#arrowPurple)"/>
100
+ <text x="790" y="170" class="arrow-label">Feedback Loop</text>
101
+ </svg>
@@ -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."