diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..d5b03b2 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,24 @@ +name: CI + +on: + push: + branches: [main, master] + pull_request: + +permissions: + contents: read + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + sanity: + runs-on: ubuntu-latest + timeout-minutes: 20 + steps: + - uses: actions/checkout@v4 + - name: Sanity + run: | + test -f README.md || test -f Readme.md || test -f readme.md || test -f README + echo "Repository sanity OK" diff --git a/README.md b/README.md index 3c02a41..61b9833 100644 --- a/README.md +++ b/README.md @@ -244,3 +244,5 @@ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file - Built for KiCad, the amazing open-source PCB design suite - Powered by Ollama for local AI processing - Thanks to the KiCad community for their support and feedback + + diff --git a/README_FR.md b/README_FR.md new file mode 100644 index 0000000..61b9833 --- /dev/null +++ b/README_FR.md @@ -0,0 +1,248 @@ +# KIC-AI Assistant + +AI-powered PCB design assistant plugin for KiCad with Ollama integration and real-time component pricing. + +![KiCad Plugin](https://img.shields.io/badge/KiCad-Plugin-blue) +![AI Powered](https://img.shields.io/badge/AI-Powered-green) +![Ollama](https://img.shields.io/badge/Ollama-Integration-orange) +![Nexar API](https://img.shields.io/badge/Nexar-Pricing-purple) + +## 🎯 Quick Start + +**Ready to use:** +- 📦 [kicad-ai-assistant-v2.3.0-with-config.zip](kicad-ai-assistant-v2.3.0-with-config.zip) (~31KB) - Latest version with configuration system + +**For developers:** +- 🔧 Clone this repository for complete source code, documentation, and screenshots + +> 🎯 **For most users**: Download the ZIP file - it's specifically prepared for KiCad's Plugin Manager! + +## ✨ Features + +- **AI Chat Interface**: Interactive dialog for PCB design assistance +- **💰 Real-time Component Pricing**: Get current pricing from multiple distributors via Nexar API +- **🔧 Configuration Management**: Easy setup with tabbed configuration dialog +- **Dual Analysis Modes**: Support for both PCB layout and schematic/circuit analysis +- **3 Interaction Levels**: Choose from Analysis, Advisory, or Assistant modes based on your needs +- **Smart Mode Detection**: AI adapts responses based on selected interaction mode +- **Design Advice**: Get practical suggestions for component placement, routing, and best practices +- **Local LLM**: Uses Ollama for privacy-focused AI processing +- **Conversation Memory**: AI remembers context throughout your design session +- **🌍 Multilingual Support**: Choose from 6 languages (English, Nederlands, Deutsch, Español, Français, Português) +- **Real-time Help**: Ask questions about your design and get instant, context-aware answers + +### 💰 Pricing Features + +- **Multi-Distributor Pricing**: Real-time pricing from Digi-Key, Mouser, Farnell and more +- **Demo Mode**: Works immediately without API keys using realistic sample data +- **API Key Management**: Secure storage of Nexar API keys with encrypted configuration +- **Bulk Pricing**: Get pricing for all components in your PCB at once +- **Smart Component Matching**: Automatic matching of component values to distributor parts +- **Pricing Tiers**: See volume pricing for different quantities + +## 📋 Requirements + +- **KiCad 9.0+** +- **Python 3.7+** +- **Ollama** with `llama3.2:3b` model +- **requests** Python package +- **Nexar API key** (optional - demo mode works without it) + +## 🚀 Installation + +### Method 1: KiCad Plugin Manager (Recommended) + +1. **Download the plugin ZIP**: [kicad-ai-assistant-v2.3.0-with-config.zip](kicad-ai-assistant-v2.3.0-with-config.zip) +2. Open KiCad → **Plugin and Content Manager** +3. Click **Install from File** +4. Select the downloaded ZIP file +5. Restart KiCad + +### Method 2: Manual Installation + +1. Download and extract the plugin +2. Copy to your KiCad plugins directory: + - **Windows**: `%APPDATA%/kicad/9.0/scripting/plugins/` + - **macOS**: `~/Library/Application Support/kicad/9.0/scripting/plugins/` + - **Linux**: `~/.config/kicad/9.0/scripting/plugins/` + +## 🔧 Setup + +### 1. Install Ollama + +Download and install Ollama from [ollama.ai](https://ollama.ai) + +### 2. Install AI Model + +```bash +ollama pull llama3.2:3b +``` + +### 3. Start Ollama Server + +```bash +ollama serve +``` + +### 4. Configure Component Pricing (Optional) + +For real-time component pricing, you can configure the Nexar API: + +1. **Get a free API key** from [Nexar](https://nexar.com/api) +2. **Open KIC-AI Assistant** in KiCad +3. **Click the ⚙️ Config button** +4. **Enter your API key** in the "API Settings" tab +5. **Click Save** + +> 🎯 **Note**: The plugin works perfectly in demo mode without any API keys! + +## 💡 Usage + +### How to Use KIC-AI Assistant + +1. **Open your KiCad project in PCB Editor** (File → Open → your_project.kicad_pcb) +2. **Click the KIC-AI robot icon** in the PCB Editor toolbar +3. **Choose analysis mode**: + - **Schematic/Circuit**: Analyze component values, connections, and circuit design + - **PCB Layout**: Analyze component placement, routing, and board layout +4. **Select language**: Choose from 6 supported languages +5. **Select AI interaction mode**: + - **🔍 Analysis Mode**: Safe recommendations only + - **📋 Advisory Mode**: Step-by-step guidance with confirmation + - **🤖 Assistant Mode**: Interactive assistance and future automation +6. **Start chatting**: Ask questions or click "Analyze" for automatic analysis +7. **Get component pricing**: Click the "💰 Pricing" button for real-time pricing +8. **Configure settings**: Click the "⚙️ Config" button to manage API keys and preferences + +### Dual Mode Capabilities + +#### 📋 Schematic Mode +- Circuit analysis and component review +- Component value validation +- Net connectivity analysis +- Circuit design recommendations +- Component selection advice + +#### 🔧 PCB Mode +- PCB layout analysis +- Component placement optimization +- Routing suggestions +- Design rule checking tips +- Manufacturing considerations + +### AI Interaction Modes + +#### 🔍 Analysis Mode (Safe) +- **What it does**: Analyzes your design and provides recommendations +- **Safety**: No modifications to your project +- **Best for**: All users, learning, getting design insights + +#### 📋 Advisory Mode (Guided) +- **What it does**: Provides step-by-step instructions with user confirmation +- **Safety**: Guides you through changes with clear steps +- **Best for**: Users who want detailed guidance + +#### 🤖 Assistant Mode (Interactive) +- **What it does**: Detailed step-by-step instructions and component-specific guidance +- **Safety**: Advanced features for experienced users +- **Best for**: Power users, complex design tasks + +### Example Questions + +**Schematic Mode:** +- "Review the power supply circuit" +- "Check if R1 value is appropriate" +- "Analyze the op-amp configuration" +- "Are there any missing decoupling capacitors?" + +**PCB Mode:** +- "How can I improve the routing on this PCB?" +- "Are there any potential EMI issues?" +- "What's the best way to place these components?" +- "Can you review my power distribution?" +- "Get pricing for all components in this design" + +### 💰 Component Pricing Usage + +The plugin includes powerful component pricing capabilities: + +**Demo Mode (No API Key Required):** +- Click "💰 Pricing" to get realistic sample pricing +- Uses demo data from major distributors (Digi-Key, Mouser, Farnell) +- Perfect for testing and evaluation + +**API Mode (With Nexar API Key):** +- Real-time pricing from actual distributors +- Up-to-date availability information +- Volume pricing tiers +- Multiple distributor comparison + +**Example Pricing Workflow:** +1. Design your PCB with component values +2. Click "💰 Pricing" button +3. View pricing breakdown by component +4. See total BOM cost and availability + +## 🌍 Language Support + +The plugin supports 6 languages with native AI responses: +- 🇬🇧 English +- 🇳🇱 Nederlands (Dutch) +- 🇩🇪 Deutsch (German) +- 🇪🇸 Español (Spanish) +- 🇫🇷 Français (French) +- 🇵🇹 Português (Portuguese) + +## 🛠️ Troubleshooting + +### Common Issues + +**"Cannot connect to Ollama"** +- Make sure Ollama is running: `ollama serve` +- Check if the model is installed: `ollama list` + +**"Requests module not available"** +- Install requests: `pip install requests` + +**Plugin doesn't appear in KiCad** +- Check plugin installation path +- Restart KiCad completely +- Check KiCad logs for errors + +## 📁 Project Structure + +``` +kic-ai-assistant/ +├── plugins/ +│ ├── __init__.py # Plugin registration +│ ├── ai_dialog.py # Main dialog and AI integration +│ ├── config_manager.py # Configuration management system +│ ├── simple_mcp_client_embedded.py # Embedded MCP client for pricing +│ ├── nexar_server.py # Nexar API server implementation +│ └── robot_icon.png # Plugin icon +├── mcp_servers/ # Model Context Protocol servers +│ └── nexar.py # External Nexar MCP server +├── screenshots/ # Interface screenshots +├── README.md # This file +├── INSTALL.md # Detailed installation guide +├── CHANGELOG.md # Version history +├── CONFIG_UPDATE_v2.3.0.md # Configuration system documentation +├── metadata.json # Plugin metadata +└── LICENSE # MIT License +``` + +## 🤝 Contributing + +Contributions are welcome! Please feel free to submit a Pull Request. + +## 📄 License + +This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details. + +## 🙏 Acknowledgments + +- Built for KiCad, the amazing open-source PCB design suite +- Powered by Ollama for local AI processing +- Thanks to the KiCad community for their support and feedback + + diff --git a/mcp_servers/kicad_symbol_sqlite.py b/mcp_servers/kicad_symbol_sqlite.py index 8cdaf99..da5e86c 100644 --- a/mcp_servers/kicad_symbol_sqlite.py +++ b/mcp_servers/kicad_symbol_sqlite.py @@ -12,7 +12,7 @@ import json from pathlib import Path import sqlite3 import tempfile -from typing import Any, Dict, List, Optional, Sequence, Tuple +from typing import Any, Dict, List, Optional, Tuple try: from .kicad_text import ( diff --git a/mcp_servers/nexar.py b/mcp_servers/nexar.py index 8f15f6e..2ea04db 100644 --- a/mcp_servers/nexar.py +++ b/mcp_servers/nexar.py @@ -10,7 +10,7 @@ import sys import asyncio import os import logging -from typing import Dict, List, Any, Optional +from typing import Dict, Any try: import requests @@ -250,14 +250,14 @@ class NexarServer: "url": "https://www.mouser.com" }, "Farnell": { - "part_number": f"9239111", + "part_number": "9239111", "unit_price": 0.025, "stock": 25000, "minimum_order": 1, "url": "https://www.farnell.com" }, "Newark": { - "part_number": f"52AC3050", + "part_number": "52AC3050", "unit_price": 0.022, "stock": 30000, "minimum_order": 10, diff --git a/plugins/__init__.py b/plugins/__init__.py index 6d1141a..07671db 100644 --- a/plugins/__init__.py +++ b/plugins/__init__.py @@ -96,7 +96,7 @@ class KicAIAssistant(pcbnew.ActionPlugin): ) return - except Exception as e: + except Exception: # Fallback to PCB mode context_type = "pcb" diff --git a/plugins/ai_dialog.py b/plugins/ai_dialog.py index 49824cd..e4b83b6 100644 --- a/plugins/ai_dialog.py +++ b/plugins/ai_dialog.py @@ -2,9 +2,6 @@ import wx import pcbnew import threading -from datetime import datetime -import json -import logging from config_manager import ConfigManager, ConfigDialog try: @@ -399,7 +396,7 @@ Choose the mode that fits your experience level and comfort with AI assistance." rotation = fp.GetOrientation().AsDegrees() # Layer (bovenkant/onderkant) - layer = "Top" if fp.IsFlipped() == False else "Bottom" + layer = "Top" if not fp.IsFlipped() else "Bottom" info.append(f"{ref}: {value}") info.append(f" Footprint: {footprint}") @@ -842,8 +839,8 @@ Would you like me to explain any of these steps in more detail?""" error_msg += "💡 This should work in demo mode without API keys.\n" error_msg += "Please check that Python3 is installed and working.\n\n" error_msg += "Debug info:\n" - error_msg += f"• Python executable: python3\n" - error_msg += f"• Server path: mcp_servers/nexar.py\n" + error_msg += "• Python executable: python3\n" + error_msg += "• Server path: mcp_servers/nexar.py\n" error_msg += f"• Working directory: {os.getcwd()}\n" wx.CallAfter(self.add_message, "❌ Error", error_msg) @@ -907,7 +904,7 @@ Would you like me to explain any of these steps in more detail?""" return # Create pricing report - report = f"💰 **COMPONENT PRICING REPORT**\n\n" + report = "💰 **COMPONENT PRICING REPORT**\n\n" report += f"Found pricing for {found_count}/{len(component_values)} unique component values:\n\n" total_cost = 0.0 diff --git a/plugins/config_dialog.py b/plugins/config_dialog.py index 2ae19d9..a2f2a1a 100644 --- a/plugins/config_dialog.py +++ b/plugins/config_dialog.py @@ -7,7 +7,7 @@ Allows users to configure MCP servers, API keys, and other settings import wx import json import os -from typing import Dict, List, Any +from typing import Dict, Any class MCPServerConfigPanel(wx.Panel): """Panel for configuring a single MCP server""" @@ -144,7 +144,7 @@ class MCPServerConfigPanel(wx.Panel): def update_field_visibility(self): """Update field visibility based on server type""" - requires_api_key = self.server_config.get('requires_api_key', False) + self.server_config.get('requires_api_key', False) # Show/hide API fields based on server type if self.server_name in ['component_database', 'kicad_tools']: @@ -193,10 +193,7 @@ class MCPServerConfigPanel(wx.Panel): """Test connection in background""" try: # Import test function - import sys import subprocess - import tempfile - import time # Create test message test_message = { diff --git a/plugins/mcp_client.py b/plugins/mcp_client.py index c75250f..8938a21 100644 --- a/plugins/mcp_client.py +++ b/plugins/mcp_client.py @@ -6,8 +6,6 @@ Enables communication with MCP servers for extended functionality import json import subprocess -import threading -import time from typing import Dict, List, Any, Optional class MCPClient: diff --git a/plugins/nexar_server.py b/plugins/nexar_server.py index dec1198..14705dc 100644 --- a/plugins/nexar_server.py +++ b/plugins/nexar_server.py @@ -7,7 +7,7 @@ Provides component search and pricing via Model Context Protocol (MCP) import json import sys import logging -from typing import Dict, List, Any, Optional +from typing import Dict, Any # Set up logging logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(message)s') diff --git a/plugins/simple_mcp_client_embedded.py b/plugins/simple_mcp_client_embedded.py index f47d210..93837e0 100644 --- a/plugins/simple_mcp_client_embedded.py +++ b/plugins/simple_mcp_client_embedded.py @@ -5,11 +5,7 @@ Simple MCP Client for Nexar API integration with embedded server fallback import json import subprocess -import time import os -import sys -import threading -import queue class EmbeddedNexarServer: """Embedded Nexar-compatible server with demo data""" diff --git a/test_component_db_interactive.py b/test_component_db_interactive.py index 892b4e5..5fe6d15 100644 --- a/test_component_db_interactive.py +++ b/test_component_db_interactive.py @@ -6,8 +6,6 @@ Shows you exactly how to communicate with the server import subprocess import json -import sys -import time def test_component_db_interactive(): """Test component_db server interactively""" diff --git a/tests/README.md b/tests/README.md new file mode 100644 index 0000000..1ba4ecd --- /dev/null +++ b/tests/README.md @@ -0,0 +1,12 @@ +# Smoke Tests + +## Objectif +Valider un niveau minimal de qualité avant optimisation. + +## Vérifications minimales +- Arborescence projet cohérente. +- README présent et à jour. +- Scripts/commandes principales documentés. + +## Critères de réussite +- Aucune erreur bloquante détectée sur les commandes de base.