|
| 1 | +# PyCharm Plugin Integration Guide |
| 2 | + |
| 3 | +This document describes the REST API for integrating PicoCode with PyCharm and other IDEs. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +PicoCode provides a production-ready local RAG backend with per-project persistent storage. Each project gets its own SQLite database for isolation, and the API is designed to be compatible with IDE plugins. |
| 8 | + |
| 9 | +## API Endpoints |
| 10 | + |
| 11 | +### Base URL |
| 12 | +``` |
| 13 | +http://127.0.0.1:8000/api |
| 14 | +``` |
| 15 | + |
| 16 | +### Health Check |
| 17 | +```http |
| 18 | +GET /api/health |
| 19 | +``` |
| 20 | + |
| 21 | +Returns server status and available features. |
| 22 | + |
| 23 | +**Response:** |
| 24 | +```json |
| 25 | +{ |
| 26 | + "status": "ok", |
| 27 | + "version": "0.2.0", |
| 28 | + "features": ["rag", "per-project-db", "pycharm-api"] |
| 29 | +} |
| 30 | +``` |
| 31 | + |
| 32 | +### Project Management |
| 33 | + |
| 34 | +#### Create/Get Project |
| 35 | +```http |
| 36 | +POST /api/projects |
| 37 | +Content-Type: application/json |
| 38 | +
|
| 39 | +{ |
| 40 | + "path": "/absolute/path/to/project", |
| 41 | + "name": "Optional Project Name" |
| 42 | +} |
| 43 | +``` |
| 44 | + |
| 45 | +Creates a new project or returns existing one. Each project gets its own database. |
| 46 | + |
| 47 | +**Response:** |
| 48 | +```json |
| 49 | +{ |
| 50 | + "id": "1234567890abcdef", |
| 51 | + "name": "MyProject", |
| 52 | + "path": "/absolute/path/to/project", |
| 53 | + "database_path": "~/.picocode/projects/1234567890abcdef.db", |
| 54 | + "created_at": "2025-11-06T14:30:00", |
| 55 | + "last_indexed_at": null, |
| 56 | + "status": "created", |
| 57 | + "settings": null |
| 58 | +} |
| 59 | +``` |
| 60 | + |
| 61 | +#### List All Projects |
| 62 | +```http |
| 63 | +GET /api/projects |
| 64 | +``` |
| 65 | + |
| 66 | +Returns list of all registered projects. |
| 67 | + |
| 68 | +**Response:** |
| 69 | +```json |
| 70 | +[ |
| 71 | + { |
| 72 | + "id": "1234567890abcdef", |
| 73 | + "name": "MyProject", |
| 74 | + "path": "/absolute/path/to/project", |
| 75 | + "status": "ready", |
| 76 | + ... |
| 77 | + } |
| 78 | +] |
| 79 | +``` |
| 80 | + |
| 81 | +#### Get Project Details |
| 82 | +```http |
| 83 | +GET /api/projects/{project_id} |
| 84 | +``` |
| 85 | + |
| 86 | +Returns details for a specific project. |
| 87 | + |
| 88 | +#### Delete Project |
| 89 | +```http |
| 90 | +DELETE /api/projects/{project_id} |
| 91 | +``` |
| 92 | + |
| 93 | +Deletes project and its database. |
| 94 | + |
| 95 | +**Response:** |
| 96 | +```json |
| 97 | +{ |
| 98 | + "success": true |
| 99 | +} |
| 100 | +``` |
| 101 | + |
| 102 | +### Indexing |
| 103 | + |
| 104 | +#### Index Project |
| 105 | +```http |
| 106 | +POST /api/projects/index |
| 107 | +Content-Type: application/json |
| 108 | +
|
| 109 | +{ |
| 110 | + "project_id": "1234567890abcdef" |
| 111 | +} |
| 112 | +``` |
| 113 | + |
| 114 | +Starts background indexing of the project. This processes all files, generates embeddings, and stores them in the project's database. |
| 115 | + |
| 116 | +**Response:** |
| 117 | +```json |
| 118 | +{ |
| 119 | + "status": "indexing", |
| 120 | + "project_id": "1234567890abcdef" |
| 121 | +} |
| 122 | +``` |
| 123 | + |
| 124 | +### Code Intelligence |
| 125 | + |
| 126 | +#### Semantic Search |
| 127 | +```http |
| 128 | +POST /api/query |
| 129 | +Content-Type: application/json |
| 130 | +
|
| 131 | +{ |
| 132 | + "project_id": "1234567890abcdef", |
| 133 | + "query": "How does authentication work?", |
| 134 | + "top_k": 5 |
| 135 | +} |
| 136 | +``` |
| 137 | + |
| 138 | +Performs semantic search across the indexed project. |
| 139 | + |
| 140 | +**Response:** |
| 141 | +```json |
| 142 | +{ |
| 143 | + "results": [ |
| 144 | + { |
| 145 | + "file_id": 123, |
| 146 | + "path": "src/auth.py", |
| 147 | + "chunk_index": 0, |
| 148 | + "score": 0.8542 |
| 149 | + } |
| 150 | + ], |
| 151 | + "project_id": "1234567890abcdef", |
| 152 | + "query": "How does authentication work?" |
| 153 | +} |
| 154 | +``` |
| 155 | + |
| 156 | +#### Code Completion / Question Answering |
| 157 | +```http |
| 158 | +POST /api/code |
| 159 | +Content-Type: application/json |
| 160 | +
|
| 161 | +{ |
| 162 | + "project_id": "1234567890abcdef", |
| 163 | + "prompt": "Explain the authentication flow", |
| 164 | + "context": "", |
| 165 | + "use_rag": true, |
| 166 | + "top_k": 5 |
| 167 | +} |
| 168 | +``` |
| 169 | + |
| 170 | +Gets code suggestions or answers using RAG + LLM. |
| 171 | + |
| 172 | +**Response:** |
| 173 | +```json |
| 174 | +{ |
| 175 | + "response": "The authentication flow works as follows...", |
| 176 | + "used_context": [ |
| 177 | + { |
| 178 | + "path": "src/auth.py", |
| 179 | + "score": 0.8542 |
| 180 | + } |
| 181 | + ], |
| 182 | + "project_id": "1234567890abcdef" |
| 183 | +} |
| 184 | +``` |
| 185 | + |
| 186 | +## PyCharm Plugin Workflow |
| 187 | + |
| 188 | +### 1. On Project Open |
| 189 | +When a project is opened in PyCharm: |
| 190 | +``` |
| 191 | +1. POST /api/projects with project path |
| 192 | +2. Store returned project_id |
| 193 | +3. Check if project needs indexing (status != "ready") |
| 194 | +4. If needed, POST /api/projects/index |
| 195 | +``` |
| 196 | + |
| 197 | +### 2. Code Assistance |
| 198 | +When user requests code help: |
| 199 | +``` |
| 200 | +1. POST /api/code with prompt and project_id |
| 201 | +2. Display response in IDE |
| 202 | +3. Show used_context sources if available |
| 203 | +``` |
| 204 | + |
| 205 | +### 3. Semantic Search |
| 206 | +When user searches for code: |
| 207 | +``` |
| 208 | +1. POST /api/query with search term and project_id |
| 209 | +2. Display matching files and scores |
| 210 | +3. Allow navigation to results |
| 211 | +``` |
| 212 | + |
| 213 | +### 4. Background Monitoring |
| 214 | +Poll project status periodically: |
| 215 | +``` |
| 216 | +1. GET /api/projects/{project_id} |
| 217 | +2. Check status field |
| 218 | +3. Update UI indicators |
| 219 | +``` |
| 220 | + |
| 221 | +## Configuration |
| 222 | + |
| 223 | +Create a `.env` file with: |
| 224 | + |
| 225 | +```bash |
| 226 | +# API endpoint for embeddings and LLM |
| 227 | +API_URL=https://api.openai.com/v1/ |
| 228 | +API_KEY=your-api-key-here |
| 229 | + |
| 230 | +# Model names |
| 231 | +EMBEDDING_MODEL=text-embedding-3-small |
| 232 | +CODING_MODEL=gpt-4o |
| 233 | + |
| 234 | +# Server configuration |
| 235 | +UVICORN_HOST=127.0.0.1 |
| 236 | +UVICORN_PORT=8000 |
| 237 | + |
| 238 | +# File processing |
| 239 | +MAX_FILE_SIZE=200000 |
| 240 | +``` |
| 241 | + |
| 242 | +## Error Handling |
| 243 | + |
| 244 | +All endpoints return standard HTTP status codes: |
| 245 | +- 200: Success |
| 246 | +- 400: Bad request (validation error) |
| 247 | +- 404: Resource not found |
| 248 | +- 500: Server error |
| 249 | + |
| 250 | +Error responses include a JSON object: |
| 251 | +```json |
| 252 | +{ |
| 253 | + "error": "Description of the error" |
| 254 | +} |
| 255 | +``` |
| 256 | + |
| 257 | +## Example Integration (Python) |
| 258 | + |
| 259 | +```python |
| 260 | +import requests |
| 261 | + |
| 262 | +class PicoCodeClient: |
| 263 | + def __init__(self, base_url="http://127.0.0.1:8000/api"): |
| 264 | + self.base_url = base_url |
| 265 | + |
| 266 | + def create_project(self, path, name=None): |
| 267 | + response = requests.post( |
| 268 | + f"{self.base_url}/projects", |
| 269 | + json={"path": path, "name": name} |
| 270 | + ) |
| 271 | + return response.json() |
| 272 | + |
| 273 | + def index_project(self, project_id): |
| 274 | + response = requests.post( |
| 275 | + f"{self.base_url}/projects/index", |
| 276 | + json={"project_id": project_id} |
| 277 | + ) |
| 278 | + return response.json() |
| 279 | + |
| 280 | + def query(self, project_id, query, top_k=5): |
| 281 | + response = requests.post( |
| 282 | + f"{self.base_url}/query", |
| 283 | + json={ |
| 284 | + "project_id": project_id, |
| 285 | + "query": query, |
| 286 | + "top_k": top_k |
| 287 | + } |
| 288 | + ) |
| 289 | + return response.json() |
| 290 | + |
| 291 | + def get_code_suggestion(self, project_id, prompt, use_rag=True): |
| 292 | + response = requests.post( |
| 293 | + f"{self.base_url}/code", |
| 294 | + json={ |
| 295 | + "project_id": project_id, |
| 296 | + "prompt": prompt, |
| 297 | + "use_rag": use_rag |
| 298 | + } |
| 299 | + ) |
| 300 | + return response.json() |
| 301 | + |
| 302 | +# Usage |
| 303 | +client = PicoCodeClient() |
| 304 | +project = client.create_project("/path/to/my/project", "MyProject") |
| 305 | +client.index_project(project["id"]) |
| 306 | +results = client.query(project["id"], "authentication flow") |
| 307 | +suggestion = client.get_code_suggestion(project["id"], "Explain auth") |
| 308 | +``` |
| 309 | + |
| 310 | +## Support |
| 311 | + |
| 312 | +For issues or questions, please refer to the main PicoCode repository. |
0 commit comments