|
| 1 | +# JetBrains Plugin Development Setup |
| 2 | + |
| 3 | +This directory contains the JetBrains plugin implementation for Kilo Code, including both the IntelliJ plugin (Kotlin) and the Extension Host (Node.js/TypeScript). |
| 4 | + |
| 5 | +## Prerequisites |
| 6 | + |
| 7 | +Before building the JetBrains plugin, ensure all dependencies are properly configured. Use the provided dependency check script to verify your setup. |
| 8 | + |
| 9 | +### Required Dependencies |
| 10 | + |
| 11 | +#### 1. Java Development Kit (JDK) 17 |
| 12 | + |
| 13 | +- **Required Version**: Java 17 (LTS) |
| 14 | +- **Why**: The plugin build system requires Java 17 for compilation and runtime compatibility |
| 15 | +- **Recommended Installation** (SDKMAN - works on macOS/Linux): |
| 16 | + |
| 17 | + ```bash |
| 18 | + # Install SDKMAN |
| 19 | + curl -s "https://get.sdkman.io" | bash |
| 20 | + source ~/.sdkman/bin/sdkman-init.sh |
| 21 | + |
| 22 | + # Install and use Java 17 |
| 23 | + sdk install java 17.0.12-tem |
| 24 | + sdk use java 17.0.12-tem |
| 25 | + ``` |
| 26 | + |
| 27 | +- **Alternative Installation**: |
| 28 | + - macOS: `brew install openjdk@17` |
| 29 | + - Linux: `sudo apt install openjdk-17-jdk` or equivalent |
| 30 | + - Windows: Download from [Oracle](https://www.oracle.com/java/technologies/javase/jdk17-archive-downloads.html) or [OpenJDK](https://openjdk.org/projects/jdk/17/) |
| 31 | + |
| 32 | +#### 2. VSCode Submodule |
| 33 | + |
| 34 | +- **Location**: `deps/vscode/` |
| 35 | +- **Purpose**: Provides VSCode runtime dependencies and APIs for the Extension Host |
| 36 | +- **Initialization**: Must be initialized before building |
| 37 | + |
| 38 | +#### 3. Node.js and pnpm |
| 39 | + |
| 40 | +- **Node.js**: Version 20.x (as specified in package.json) |
| 41 | +- **pnpm**: For workspace management and dependency installation |
| 42 | + |
| 43 | +## Quick Setup |
| 44 | + |
| 45 | +The dependency check runs automatically as part of the build process, but you can also run it manually: |
| 46 | + |
| 47 | +```bash |
| 48 | +# Run dependency check manually |
| 49 | +./jetbrains/scripts/check-dependencies.sh |
| 50 | +
|
| 51 | +# Or as part of JetBrains host build process |
| 52 | +cd jetbrains/host && pnpm run deps:check |
| 53 | +``` |
| 54 | + |
| 55 | +**Note**: The dependency check is automatically integrated into the Turbo build system and runs before JetBrains builds to ensure all dependencies are properly configured. |
| 56 | + |
| 57 | +### Quick Fixes for Common Issues |
| 58 | + |
| 59 | +- **"Unsupported class file major version 68"**: [Install Java 17](#java-version-issues) |
| 60 | +- **"slice is not valid mach-o file"**: [Rebuild native modules](#native-module-architecture-mismatch) |
| 61 | +- **"platform.zip file does not exist"**: [Generate platform files](#missing-platformzip) |
| 62 | + |
| 63 | +## Manual Setup |
| 64 | + |
| 65 | +If you prefer to set up dependencies manually: |
| 66 | + |
| 67 | +### 1. Initialize VSCode Submodule |
| 68 | + |
| 69 | +```bash |
| 70 | +# From project root |
| 71 | +git submodule update --init --recursive |
| 72 | +``` |
| 73 | + |
| 74 | +### 2. Verify Java Version |
| 75 | + |
| 76 | +```bash |
| 77 | +java -version |
| 78 | +# Should show Java 17.x.x |
| 79 | +
|
| 80 | +javac -version |
| 81 | +# Should show javac 17.x.x |
| 82 | +``` |
| 83 | + |
| 84 | +### 3. Install Node Dependencies |
| 85 | + |
| 86 | +```bash |
| 87 | +# From project root |
| 88 | +pnpm install |
| 89 | +``` |
| 90 | + |
| 91 | +## Project Structure |
| 92 | + |
| 93 | +``` |
| 94 | +jetbrains/ |
| 95 | +├── host/ # Extension Host (Node.js/TypeScript) |
| 96 | +│ ├── src/ # TypeScript source code |
| 97 | +│ ├── package.json # Node.js dependencies |
| 98 | +│ ├── tsconfig.json # TypeScript configuration |
| 99 | +│ └── turbo.json # Turbo build configuration |
| 100 | +├── plugin/ # IntelliJ Plugin (Kotlin/Java) |
| 101 | +│ ├── src/main/kotlin/ # Kotlin source code |
| 102 | +│ ├── src/main/resources/ # Plugin resources and themes |
| 103 | +│ ├── build.gradle.kts # Gradle build configuration |
| 104 | +│ ├── gradle.properties # Plugin version and platform settings |
| 105 | +│ ├── genPlatform.gradle # VSCode platform generation |
| 106 | +│ └── scripts/ # Build and utility scripts |
| 107 | +├── resources/ # Runtime resources (generated) |
| 108 | +└── README.md # This file |
| 109 | +``` |
| 110 | + |
| 111 | +## Build Modes |
| 112 | + |
| 113 | +The plugin supports three build modes controlled by the `debugMode` property: |
| 114 | + |
| 115 | +### 1. Development Mode (`debugMode=idea`) |
| 116 | + |
| 117 | +```bash |
| 118 | +./gradlew prepareSandbox -PdebugMode=idea |
| 119 | +``` |
| 120 | + |
| 121 | +- Used for local development and debugging |
| 122 | +- Creates `.env` file for Extension Host |
| 123 | +- Copies theme resources to debug location |
| 124 | +- Enables hot-reloading for VSCode plugin integration |
| 125 | + |
| 126 | +### 2. Release Mode (`debugMode=release`) |
| 127 | + |
| 128 | +```bash |
| 129 | +./gradlew prepareSandbox -PdebugMode=release |
| 130 | +``` |
| 131 | + |
| 132 | +- Used for production builds |
| 133 | +- Requires `platform.zip` file (generated via `genPlatform` task) |
| 134 | +- Creates fully self-contained deployment package |
| 135 | +- Includes all runtime dependencies and node_modules |
| 136 | + |
| 137 | +### 3. Lightweight Mode (`debugMode=none`, default) |
| 138 | + |
| 139 | +```bash |
| 140 | +./gradlew prepareSandbox |
| 141 | +``` |
| 142 | + |
| 143 | +- Used for testing and CI |
| 144 | +- Minimal resource preparation |
| 145 | +- No VSCode runtime dependencies |
| 146 | +- Suitable for static analysis and unit tests |
| 147 | + |
| 148 | +## Building the Plugin |
| 149 | + |
| 150 | +### Development Build |
| 151 | + |
| 152 | +```bash |
| 153 | +# From project root |
| 154 | +pnpm jetbrains:run |
| 155 | +
|
| 156 | +# Or manually: |
| 157 | +cd jetbrains/plugin |
| 158 | +./gradlew runIde -PdebugMode=idea |
| 159 | +``` |
| 160 | + |
| 161 | +### Production Build |
| 162 | + |
| 163 | +```bash |
| 164 | +# Generate platform files first (if needed) |
| 165 | +cd jetbrains/plugin |
| 166 | +./gradlew genPlatform |
| 167 | +
|
| 168 | +# Build plugin |
| 169 | +./gradlew buildPlugin -PdebugMode=release |
| 170 | +``` |
| 171 | + |
| 172 | +### Extension Host Only |
| 173 | + |
| 174 | +```bash |
| 175 | +# From jetbrains/host directory |
| 176 | +pnpm build |
| 177 | +
|
| 178 | +# Or with Turbo from project root |
| 179 | +pnpm --filter @kilo-code/jetbrains-host build |
| 180 | +``` |
| 181 | + |
| 182 | +## Turbo Integration |
| 183 | + |
| 184 | +The project uses Turborepo for efficient builds and caching: |
| 185 | + |
| 186 | +- **`jetbrains:bundle`**: Builds the complete plugin bundle |
| 187 | +- **`jetbrains:run-bundle`**: Runs the plugin with bundle mode |
| 188 | +- **`jetbrains:run`**: Runs the plugin in development mode |
| 189 | + |
| 190 | +Turbo automatically handles: |
| 191 | + |
| 192 | +- VSCode submodule initialization (`deps:check`) |
| 193 | +- Dependency patching (`deps:patch`) |
| 194 | +- Build caching and parallelization |
| 195 | + |
| 196 | +## Common Issues and Troubleshooting |
| 197 | + |
| 198 | +### Java Version Issues |
| 199 | + |
| 200 | +**Problem**: Build fails with "Unsupported class file major version 68" or similar Java version errors |
| 201 | +**Root Cause**: Running Java 24+ instead of required Java 17 |
| 202 | + |
| 203 | +**Solution**: |
| 204 | + |
| 205 | +#### Option 1: Using SDKMAN (Recommended for macOS/Linux) |
| 206 | + |
| 207 | +```bash |
| 208 | +# Install SDKMAN if not already installed |
| 209 | +curl -s "https://get.sdkman.io" | bash |
| 210 | +source ~/.sdkman/bin/sdkman-init.sh |
| 211 | +
|
| 212 | +# Install and use Java 17 |
| 213 | +sdk install java 17.0.12-tem |
| 214 | +sdk use java 17.0.12-tem |
| 215 | +
|
| 216 | +# Make Java 17 default (optional) |
| 217 | +sdk default java 17.0.12-tem |
| 218 | +
|
| 219 | +# Verify version |
| 220 | +java -version # Should show OpenJDK 17.x.x |
| 221 | +``` |
| 222 | + |
| 223 | +#### Option 2: Using Homebrew (macOS Alternative) |
| 224 | + |
| 225 | +```bash |
| 226 | +# Install Java 17 |
| 227 | +brew install openjdk@17 |
| 228 | +
|
| 229 | +# Set JAVA_HOME for current session |
| 230 | +export JAVA_HOME=/opt/homebrew/opt/openjdk@17/libexec/openjdk.jdk/Contents/Home |
| 231 | +
|
| 232 | +# Add to shell profile for persistence |
| 233 | +echo 'export JAVA_HOME=/opt/homebrew/opt/openjdk@17/libexec/openjdk.jdk/Contents/Home' >> ~/.zshrc |
| 234 | +
|
| 235 | +# Verify version |
| 236 | +java -version |
| 237 | +``` |
| 238 | + |
| 239 | +#### Option 3: Manual JAVA_HOME Setup |
| 240 | + |
| 241 | +```bash |
| 242 | +# Find Java 17 installation |
| 243 | +/usr/libexec/java_home -V |
| 244 | +
|
| 245 | +# Set JAVA_HOME to Java 17 path |
| 246 | +export JAVA_HOME=$(/usr/libexec/java_home -v 17) |
| 247 | +``` |
| 248 | + |
| 249 | +### VSCode Submodule Not Initialized |
| 250 | + |
| 251 | +**Problem**: Build fails with missing VSCode dependencies |
| 252 | +**Solution**: |
| 253 | + |
| 254 | +```bash |
| 255 | +# Initialize submodule |
| 256 | +git submodule update --init --recursive |
| 257 | +
|
| 258 | +# Verify submodule is populated |
| 259 | +ls deps/vscode/src # Should contain VSCode source files |
| 260 | +``` |
| 261 | + |
| 262 | +### Missing platform.zip |
| 263 | + |
| 264 | +**Problem**: Release build fails with "platform.zip file does not exist" |
| 265 | +**Solution**: |
| 266 | + |
| 267 | +```bash |
| 268 | +cd jetbrains/plugin |
| 269 | +./gradlew genPlatform # This will download and generate platform.zip |
| 270 | +``` |
| 271 | + |
| 272 | +### Node.js Version Mismatch |
| 273 | + |
| 274 | +**Problem**: Extension Host build fails with Node.js compatibility errors |
| 275 | +**Solution**: |
| 276 | + |
| 277 | +```bash |
| 278 | +# Use Node.js 20.x |
| 279 | +nvm use 20 # if using nvm |
| 280 | +# or |
| 281 | +node --version # should show v20.x.x |
| 282 | +``` |
| 283 | + |
| 284 | +### Native Module Architecture Mismatch |
| 285 | + |
| 286 | +**Problem**: Plugin fails to load with "slice is not valid mach-o file" errors for native modules like `@vscode/spdlog` or `native-watchdog` |
| 287 | +**Root Cause**: Native Node.js modules were compiled for wrong CPU architecture (e.g., x86_64 vs ARM64) |
| 288 | + |
| 289 | +**Solution**: |
| 290 | + |
| 291 | +```bash |
| 292 | +# Navigate to resources directory and rebuild native modules |
| 293 | +cd jetbrains/resources |
| 294 | +
|
| 295 | +# Clean existing modules |
| 296 | +rm -rf node_modules package-lock.json |
| 297 | +
|
| 298 | +# Copy package.json from host |
| 299 | +cp ../host/package.json . |
| 300 | +
|
| 301 | +# Install dependencies with npm (not pnpm to avoid workspace conflicts) |
| 302 | +npm install |
| 303 | +
|
| 304 | +# Verify native modules are built for correct architecture |
| 305 | +file node_modules/@vscode/spdlog/build/Release/spdlog.node |
| 306 | +file node_modules/native-watchdog/build/Release/watchdog.node |
| 307 | +# Should show "Mach-O 64-bit bundle arm64" on Apple Silicon or appropriate arch |
| 308 | +
|
| 309 | +# Update production dependency list |
| 310 | +cd ../plugin |
| 311 | +npm ls --omit=dev --all --parseable --prefix ../resources > ./prodDep.txt |
| 312 | +
|
| 313 | +# Rebuild plugin |
| 314 | +./gradlew buildPlugin -PdebugMode=none |
| 315 | +``` |
| 316 | + |
| 317 | +**Prevention**: When updating dependencies or switching architectures, always rebuild native modules in the `jetbrains/resources/` directory. |
| 318 | + |
| 319 | +### Gradle Build Issues |
| 320 | + |
| 321 | +**Problem**: Gradle tasks fail or hang |
| 322 | +**Solution**: |
| 323 | + |
| 324 | +```bash |
| 325 | +# Clean and rebuild |
| 326 | +./gradlew clean |
| 327 | +./gradlew build --refresh-dependencies |
| 328 | +
|
| 329 | +# Check Gradle daemon |
| 330 | +./gradlew --stop |
| 331 | +./gradlew build |
| 332 | +``` |
| 333 | + |
| 334 | +## Development Workflow |
| 335 | + |
| 336 | +1. **Initial Setup**: Dependencies are automatically checked when you run any JetBrains build command |
| 337 | +2. **Development**: Use `pnpm jetbrains:run` for live development (includes automatic dependency check) |
| 338 | +3. **Testing**: Build with `debugMode=none` for CI/testing |
| 339 | +4. **Release**: Generate platform files and build with `debugMode=release` |
| 340 | + |
| 341 | +**Automatic Dependency Management**: The build system now automatically verifies and sets up all required dependencies (Java 17, VSCode submodule, Node.js, etc.) before each build, ensuring a smooth development experience. |
| 342 | + |
| 343 | +## Environment Variables |
| 344 | + |
| 345 | +The plugin respects these environment variables: |
| 346 | + |
| 347 | +- `JAVA_HOME`: Java installation directory |
| 348 | +- `debugMode`: Build mode (idea/release/none) |
| 349 | +- `vscodePlugin`: Plugin name (default: kilocode) |
| 350 | +- `vscodeVersion`: VSCode version for platform generation (default: 1.100.0) |
| 351 | + |
| 352 | +## Platform Support |
| 353 | + |
| 354 | +The plugin supports multiple platforms through the platform generation system: |
| 355 | + |
| 356 | +- **Windows**: x64 |
| 357 | +- **macOS**: x64 and ARM64 (Apple Silicon) |
| 358 | +- **Linux**: x64 |
| 359 | + |
| 360 | +Platform-specific dependencies are automatically handled during the build process. |
| 361 | + |
| 362 | +**Multi-Architecture Support**: The platform generation system now includes enhanced architecture-aware native module handling, automatically creating runtime loaders that detect the current platform and load the correct native modules for each architecture. |
| 363 | + |
| 364 | +## Contributing |
| 365 | + |
| 366 | +When making changes to the JetBrains plugin: |
| 367 | + |
| 368 | +1. Ensure all dependencies are properly set up |
| 369 | +2. Test in development mode first (`debugMode=idea`) |
| 370 | +3. Verify builds work in all three modes |
| 371 | +4. Update this README if adding new dependencies or requirements |
| 372 | +5. Run the dependency check script to validate setup |
| 373 | + |
| 374 | +## Scripts |
| 375 | + |
| 376 | +- `jetbrains/scripts/check-dependencies.sh`: Comprehensive dependency verification and setup |
| 377 | +- `jetbrains/plugin/scripts/sync_version.js`: Version synchronization utility |
| 378 | + |
| 379 | +For more detailed build information, see the individual `package.json` and `build.gradle.kts` files in the respective directories. |
0 commit comments