# agcanvas A system-level interactive canvas for agent-human collaboration. Paste SVGs from Figma, get structured understanding, iterate with AI agents. ## What is this? agcanvas bridges the gap between visual design and code generation. It's not a design tool—it's a **feedback tool** for rapid iteration between humans and AI agents. ``` ┌─────────────────────────────────────────────────────────┐ │ Figma agcanvas │ │ ┌─────┐ Copy SVG ┌──────────────────────────────┐ │ │ │ │ ───────────► │ Canvas (pan/zoom) │ │ │ │Frame│ │ ┌────────┐ ┌────────┐ │ │ │ │ │ │ │ Parsed │ │ Agent │ │ │ │ └─────┘ │ │ Tree │ │ Server │ │ │ │ │ └────────┘ └───┬────┘ │ │ │ └──────────────────┼──────────┘ │ │ │ │ │ AI Agent ◄───── WebSocket (JSON) ────────┘ │ │ - Sees structure │ │ - Describes semantically │ │ - Generates code │ └─────────────────────────────────────────────────────────┘ ``` ## Features - **SVG Paste** — Copy frames from Figma, paste directly (Cmd+V) - **Structure Parsing** — SVG → typed element tree (groups, rects, circles, paths, text, images) - **Semantic Description** — Auto-generates human-readable structure description - **Agent Protocol** — WebSocket server for AI agents to query and understand the canvas - **Code Generation** — Stubs for React, HTML, Tailwind, Svelte, Vue - **Pan/Zoom** — Smooth canvas navigation ## Installation ### From source ```bash git clone https://github.com/yourusername/agcanvas.git cd agcanvas cargo build --release ./target/release/agcanvas ``` ### Requirements - Rust 1.70+ - macOS / Linux / Windows ## Usage ### Basic workflow 1. **Open agcanvas** ```bash cargo run --release ``` 2. **Copy SVG from Figma** - Select a frame in Figma - Right-click → Copy as SVG (or Cmd+C) 3. **Paste into agcanvas** - Cmd+V (or File → Paste SVG) 4. **Navigate** - **Pan**: Middle-click drag, or Cmd+drag - **Zoom**: Scroll wheel - **Reset**: Cmd+0 5. **Inspect** - View → Element Tree (hierarchical structure) - View → Description (semantic text) ### Keyboard shortcuts | Action | Shortcut | |--------|----------| | Paste SVG | Cmd+V | | Reset zoom | Cmd+0 | ## Agent Protocol agcanvas exposes a WebSocket server on `ws://127.0.0.1:9876` for AI agents to interact with the canvas. ### Connecting ```python import websocket import json ws = websocket.create_connection("ws://127.0.0.1:9876") ``` ### Requests #### Get full element tree ```json {"type": "GetTree"} ``` Response: ```json { "type": "Tree", "tree": { "root": { "id": "frame-1", "kind": {"type": "Group", "name": "Login Form"}, "bounds": {"x": 0, "y": 0, "width": 400, "height": 600}, "children": [...] }, "metadata": { "source": "svg_paste", "width": 400, "height": 600, "element_count": 15 } } } ``` #### Get semantic description ```json {"type": "Describe"} ``` Response: ```json { "type": "Description", "text": "- Group 'Login Form'\n - Rectangle (400x600) fill=#ffffff\n - Text 'Welcome Back' (24px)\n - Rectangle (320x48) fill=#f0f0f0\n - Text 'Email' (14px)\n ..." } ``` #### Generate code ```json {"type": "GenerateCode", "target": "react", "element_id": null} ``` Targets: `html`, `react`, `tailwind`, `svelte`, `vue` Response: ```json { "type": "Code", "code": "// Generated from SVG...\nexport function Component() {\n return (\n