Skip to content

Commit 9759e8e

Browse files
CopilotMte90
andauthored
Migrate to unified project-based architecture with PyCharm chat plugin and production optimizations (#1)
Co-authored-by: Mte90 <403283+Mte90@users.noreply.github.com> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
1 parent 33763d3 commit 9759e8e

File tree

20 files changed

+1791
-518
lines changed

20 files changed

+1791
-518
lines changed

.github/workflows/build-plugin.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: Build PyCharm Plugin
2+
3+
on:
4+
release:
5+
types: [created, published]
6+
workflow_dispatch:
7+
8+
jobs:
9+
build:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- uses: actions/checkout@v3
14+
15+
- name: Set up JDK 17
16+
uses: actions/setup-java@v3
17+
with:
18+
java-version: '17'
19+
distribution: 'temurin'
20+
21+
- name: Setup Gradle
22+
uses: gradle/gradle-build-action@v2
23+
24+
- name: Build plugin
25+
run: |
26+
cd plugin
27+
./gradlew buildPlugin
28+
29+
- name: Get plugin version
30+
id: plugin_version
31+
run: |
32+
cd plugin
33+
VERSION=$(grep "^version" build.gradle.kts | cut -d'"' -f2)
34+
echo "version=$VERSION" >> $GITHUB_OUTPUT
35+
36+
- name: Upload plugin artifact
37+
uses: actions/upload-artifact@v3
38+
with:
39+
name: picocode-plugin-${{ steps.plugin_version.outputs.version }}
40+
path: plugin/build/distributions/*.zip
41+
42+
- name: Upload to Release
43+
if: github.event_name == 'release'
44+
uses: softprops/action-gh-release@v1
45+
with:
46+
files: plugin/build/distributions/*.zip
47+
env:
48+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ codebase.*
44
picocode.egg-info
55
uv.lock
66
__pycache__
7+
# Per-project databases
8+
.picocode/

PYCHARM_INTEGRATION.md

Lines changed: 312 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,312 @@
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.

README.md

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,26 @@ This tool is a way to achieve this!
99

1010
## Overview
1111

12-
- Indexes files, computes embeddings using an OpenAI-compatible embedding endpoint, stores data in SQLite (with SQlite-vector).
13-
- Reads dependencies by running `python -m pip list --format=json` inside a virtualenv when available.
14-
- Detects Astral "uv" usage (https://docs.astral.sh/uv/) by inspecting `pyproject.toml` and/or installed packages in a venv; if uv is detected it tries to locate a venv managed by uv and uses it for `pip list`.
15-
- Analysis runs asynchronously (FastAPI BackgroundTasks) so the UI remains responsive.
16-
- Minimal web UI for starting analysis and asking questions (semantic search + coding model).
12+
- **Production-ready RAG backend** with per-project persistent storage
13+
- **PyCharm/IDE integration** via REST API (see [PYCHARM_INTEGRATION.md](PYCHARM_INTEGRATION.md))
14+
- **Per-project databases**: Each project gets isolated SQLite database
15+
- Indexes files, computes embeddings using an OpenAI-compatible embedding endpoint
16+
- Stores vector embeddings in SQLite using sqlite-vector for fast semantic search
17+
- Analysis runs asynchronously (FastAPI BackgroundTasks) so the UI remains responsive
18+
- Minimal web UI for starting analysis and asking questions (semantic search + coding model)
19+
- Health check and monitoring endpoints for production deployment
20+
21+
### PyCharm Plugin
22+
23+
A full-featured PyCharm/IntelliJ IDEA plugin is available in the `plugin/` directory:
24+
25+
- **Per-Project Indexing**: Automatically indexes current project
26+
- **Secure API Keys**: Stores credentials in IDE password safe
27+
- **Real-time Responses**: Streams answers from your coding model
28+
- **File Navigation**: Click retrieved files to open in editor
29+
- **Progress Indicators**: Visual feedback during indexing
30+
31+
See [plugin/README.md](plugin/README.md) for installation and usage instructions.
1732

1833
Prerequisites
1934
- Python 3.8+ (3.11+ recommended for builtin tomllib)

0 commit comments

Comments
 (0)