Skip to content

Commit 2d67413

Browse files
committed
fix: minor fixes to the cursor extension integraiton and installation
1 parent 36a3c78 commit 2d67413

File tree

3 files changed

+146
-29
lines changed

3 files changed

+146
-29
lines changed

CURSOR_README.md

Lines changed: 55 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,18 @@ This extension integrates the Ignition RAG (Retrieval-Augmented Generation) syst
1111

1212
## Installation
1313

14-
### Option 1: Using the installation script
14+
### Option 1: Using the installation script (Recommended)
1515

1616
1. Run the installation script:
1717
```bash
1818
./install_cursor_extension.sh
1919
```
2020

21+
The script will:
22+
- Create a virtual environment for Python dependencies
23+
- Install required packages in the isolated environment
24+
- Configure the extension to use the virtual environment
25+
2126
2. Restart Cursor to enable the extension
2227

2328
### Option 2: Manual installation
@@ -27,18 +32,60 @@ This extension integrates the Ignition RAG (Retrieval-Augmented Generation) syst
2732
mkdir -p ~/.cursor/extensions/ignition-rag
2833
```
2934

30-
2. Copy the extension files:
35+
2. Create a virtual environment for Python dependencies:
36+
```bash
37+
python3 -m venv ~/.cursor/extensions/ignition-rag/venv
38+
```
39+
40+
3. Install required Python packages:
41+
```bash
42+
~/.cursor/extensions/ignition-rag/venv/bin/pip install requests python-dotenv
43+
```
44+
45+
4. Copy the extension files:
46+
```bash
47+
cp cursor_extension.js cursor_client.py cursor.config.json cursor_integration.js cursor_connector.js ~/.cursor/extensions/ignition-rag/
48+
```
49+
50+
5. Create a shell script wrapper for the Python client:
3151
```bash
32-
cp cursor_extension.js cursor_client.py cursor.config.json ~/.cursor/extensions/ignition-rag/
52+
echo '#!/bin/bash
53+
~/.cursor/extensions/ignition-rag/venv/bin/python3 ~/.cursor/extensions/ignition-rag/cursor_client.py "$@"' > ~/.cursor/extensions/ignition-rag/run_client.sh
54+
chmod +x ~/.cursor/extensions/ignition-rag/run_client.sh
3355
```
3456

35-
3. Create a .env file in the extension directory:
57+
6. Create a .env file in the extension directory:
3658
```
3759
RAG_API_URL=http://localhost:8001
38-
PYTHON_PATH=python3
60+
PYTHON_PATH=~/.cursor/extensions/ignition-rag/venv/bin/python3
61+
```
62+
63+
7. Restart Cursor to enable the extension
64+
65+
## Troubleshooting Installation
66+
67+
### External Environment Errors
68+
69+
If you encounter an error about "externally-managed-environment" during installation, this is because your system Python is protected from modifications. The installation script will handle this by creating a virtual environment, but if you encounter issues:
70+
71+
1. Check that the Python venv module is installed:
72+
```bash
73+
# On macOS with Homebrew
74+
brew install python-venv
75+
76+
# On Ubuntu/Debian
77+
sudo apt-get install python3-venv
3978
```
4079

41-
4. Restart Cursor to enable the extension
80+
2. If you still have issues, manually install the dependencies:
81+
```bash
82+
pip3 install --user requests python-dotenv
83+
```
84+
85+
3. Edit the `.env` file to point to your system Python:
86+
```
87+
PYTHON_PATH=python3
88+
```
4289

4390
## Usage
4491

@@ -60,7 +107,7 @@ You can configure the extension by editing the `.env` file in the extension dire
60107
```
61108
# Ignition RAG Extension Configuration
62109
RAG_API_URL=http://localhost:8001 # URL of your RAG API
63-
PYTHON_PATH=python3 # Path to Python interpreter
110+
PYTHON_PATH=/path/to/python # Path to Python interpreter (usually automatic)
64111
```
65112

66113
## Requirements
@@ -77,6 +124,7 @@ If the extension is not working as expected:
77124
2. Check the Cursor console for error messages (Help > Toggle Developer Tools)
78125
3. Verify that Python is installed and accessible
79126
4. Make sure the extension is correctly installed in `~/.cursor/extensions/ignition-rag/`
127+
5. Verify the virtual environment was created successfully at `~/.cursor/extensions/ignition-rag/venv/`
80128

81129
## License
82130

cursor_extension.js

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,20 @@ const path = require('path');
66
const fs = require('fs');
77

88
// Configuration
9-
const DEFAULT_RAG_API_URL = 'http://localhost:8001';
9+
const DEFAULT_RAG_API_URL = process.env.RAG_API_URL || 'http://localhost:8001';
1010
const DEFAULT_PYTHON_SCRIPT = path.join(__dirname, 'cursor_client.py');
11+
const SHELL_SCRIPT_WRAPPER = path.join(__dirname, 'run_client.sh');
1112

1213
// Extension configuration
1314
let config = {
1415
ragApiUrl: process.env.RAG_API_URL || DEFAULT_RAG_API_URL,
1516
pythonPath: process.env.PYTHON_PATH || 'python3',
16-
clientScript: DEFAULT_PYTHON_SCRIPT,
17+
clientScript: fs.existsSync(SHELL_SCRIPT_WRAPPER) ? SHELL_SCRIPT_WRAPPER : DEFAULT_PYTHON_SCRIPT,
1718
enabled: true,
1819
topK: 3,
1920
};
2021

21-
// Check if the Python script exists
22+
// Check if the client script exists
2223
function verifySetup() {
2324
try {
2425
if (!fs.existsSync(config.clientScript)) {
@@ -55,17 +56,35 @@ async function getIgnitionContext(query, context = {}) {
5556
// Get current file path from cursor context
5657
const currentFile = context.currentFile || '';
5758

58-
// Prepare arguments for Python script
59-
const args = [
60-
config.clientScript,
61-
query,
62-
'--file', currentFile,
63-
'--top-k', config.topK.toString(),
64-
'--output', 'text'
65-
];
59+
// Determine if we're using the shell script wrapper
60+
const isUsingWrapper = config.clientScript.endsWith('run_client.sh');
61+
62+
// Prepare arguments for Python script or shell wrapper
63+
let args = [];
64+
if (isUsingWrapper) {
65+
// Shell script already includes the path to the Python script
66+
args = [
67+
query,
68+
'--file', currentFile,
69+
'--top-k', config.topK.toString(),
70+
'--output', 'text'
71+
];
72+
} else {
73+
// Using Python directly
74+
args = [
75+
config.clientScript,
76+
query,
77+
'--file', currentFile,
78+
'--top-k', config.topK.toString(),
79+
'--output', 'text'
80+
];
81+
}
6682

67-
// Spawn Python process
68-
const process = spawn(config.pythonPath, args, {
83+
// Prepare the command to run
84+
const command = isUsingWrapper ? config.clientScript : config.pythonPath;
85+
86+
// Spawn process
87+
const process = spawn(command, args, {
6988
env: { ...process.env, RAG_API_URL: config.ragApiUrl }
7089
});
7190

install_cursor_extension.sh

Lines changed: 59 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ set -e
77
EXTENSION_NAME="ignition-rag"
88
CURSOR_EXTENSIONS_DIR="$HOME/.cursor/extensions"
99
EXTENSION_DIR="$CURSOR_EXTENSIONS_DIR/$EXTENSION_NAME"
10+
VENV_DIR="$EXTENSION_DIR/venv"
1011

1112
# Check if cursor extension directory exists
1213
if [ ! -d "$CURSOR_EXTENSIONS_DIR" ]; then
@@ -45,7 +46,20 @@ cat > "$EXTENSION_DIR/extension.js" << EOF
4546
// Ignition RAG Extension Loader
4647
// This file is automatically loaded by Cursor on startup
4748
49+
const { spawn } = require('child_process');
50+
const path = require('path');
51+
52+
// Update the Python path in the extension
4853
try {
54+
const fs = require('fs');
55+
const extensionConfig = require('./cursor_extension');
56+
57+
// Use the shell script wrapper to run the Python client
58+
extensionConfig.configure({
59+
clientScript: path.join(__dirname, 'run_client.sh'),
60+
pythonPath: '' // Not needed as the shell script handles this
61+
});
62+
4963
// Load the connector
5064
require('./cursor_connector');
5165
console.log('Ignition RAG Extension loaded successfully');
@@ -56,16 +70,38 @@ EOF
5670

5771
# Check if Python is installed
5872
if ! command -v python3 &> /dev/null; then
59-
echo "Warning: python3 not found. You may need to install Python 3 for the extension to work."
73+
echo "Warning: python3 not found. You need to install Python 3 for the extension to work."
74+
exit 1
6075
fi
6176

62-
# Check if pip is installed
63-
if command -v pip3 &> /dev/null; then
64-
echo "Installing Python dependencies..."
65-
pip3 install requests python-dotenv
66-
else
67-
echo "Warning: pip3 not found. You may need to install Python dependencies manually."
68-
echo "Required packages: requests, python-dotenv"
77+
# Install Python dependencies
78+
echo "Setting up Python dependencies..."
79+
80+
# Create a virtual environment for the extension
81+
echo "Creating a virtual environment..."
82+
python3 -m venv "$VENV_DIR" || {
83+
echo "Failed to create virtual environment. Python venv module might be missing."
84+
echo "You may need to install it manually:"
85+
echo " On macOS: brew install python-venv"
86+
echo " On Ubuntu/Debian: apt-get install python3-venv"
87+
echo ""
88+
echo "Alternatively, you can install the required packages manually:"
89+
echo " pip3 install --user requests python-dotenv"
90+
echo ""
91+
echo "Warning: Dependencies not installed automatically!"
92+
HAS_VENV=false
93+
}
94+
95+
# If venv was created successfully, install dependencies
96+
if [ -d "$VENV_DIR" ]; then
97+
echo "Installing dependencies in virtual environment..."
98+
"$VENV_DIR/bin/pip" install requests python-dotenv || {
99+
echo "Failed to install dependencies in virtual environment."
100+
echo "You may need to install them manually:"
101+
echo " pip3 install --user requests python-dotenv"
102+
}
103+
echo "Dependencies installed successfully in virtual environment."
104+
HAS_VENV=true
69105
fi
70106

71107
# Create .env file for the extension
@@ -74,10 +110,24 @@ if [ ! -f "$EXTENSION_DIR/.env" ]; then
74110
cat > "$EXTENSION_DIR/.env" << EOF
75111
# Ignition RAG Extension Configuration
76112
RAG_API_URL=http://localhost:8001
77-
PYTHON_PATH=python3
113+
PYTHON_PATH=$([ "$HAS_VENV" = true ] && echo "$VENV_DIR/bin/python3" || echo "python3")
78114
EOF
79115
fi
80116

117+
# Create a shell script to run the client with the virtual environment
118+
cat > "$EXTENSION_DIR/run_client.sh" << EOF
119+
#!/bin/bash
120+
$([ "$HAS_VENV" = true ] && echo "$VENV_DIR/bin/python3" || echo "python3") "$EXTENSION_DIR/cursor_client.py" "\$@"
121+
EOF
122+
chmod +x "$EXTENSION_DIR/run_client.sh"
123+
124+
echo ""
81125
echo "Ignition RAG extension has been installed to $EXTENSION_DIR"
126+
if [ "$HAS_VENV" = true ]; then
127+
echo "✅ Virtual environment created and dependencies installed successfully."
128+
else
129+
echo "⚠️ Virtual environment setup failed. You may need to install dependencies manually:"
130+
echo " pip3 install --user requests python-dotenv"
131+
fi
82132
echo "To configure the extension, edit $EXTENSION_DIR/.env"
83133
echo "Restart Cursor to enable the extension"

0 commit comments

Comments
 (0)