RunVSAgent Documentation

repository·main·Indexed 20 days ago

https://github.com/wecode-ai/runvsagent

A cross-platform tool that enables VSCode-based coding agents, such as Cline, Roo Code, and Kilo Code, to run inside JetBrains IDEs. It provides a VSCode API compatibility layer via a Node.js extension host and a Kotlin-based JetBrains plugin, utilizing RPC communication over Unix Domain Sockets or Named Pipes.

Tokens
29.7K
Snippets
72
Records
94
Agent score
71%

What's inside RunVSAgent

  1. How extension availability is detected

    main

    The ClineExtensionProvider.isAvailable(project) method determines if the extension can be used by checking two primary locations:

    1. Project/User Space Directory: Checks if files exist at ${VsixManager.getBaseDirectory()}/${config.codeDir} (where codeDir is retrieved from ExtensionConfiguration).
    2. Plugin Built-in Resources: If not found in the user space, it checks the plugin's internal resources using PluginResourceUtil.getResourcePath(PLUGIN_ID, config.codeDir).

    If files are found in either location, the method returns true.

    override fun isAvailable(project: Project): Boolean {
        // Check if roo-code extension files exist
        val extensionConfig = ExtensionConfiguration.getInstance(project)
        val config = extensionConfig.getConfig(ExtensionType.CLINE)
    
        // First check project paths
        val possiblePaths = listOf(
            "${getBaseDirectory()}/${config.codeDir}"
        )
    
        if (possiblePaths.any { File(it).exists() }) {
            return true
        }
    
        // Then check plugin resources (for built-in extensions)
        try {
            val pluginResourcePath = PluginResourceUtil.getResourcePath(
                PluginConstants.PLUGIN_ID,
                config.codeDir
            )
            if (pluginResourcePath != null && File(pluginResourcePath).exists()) {
                return true
            }
        } catch (e: Exception) {
            // Ignore exceptions when checking plugin resources
        }
    
        return false
    }
  2. Handle commands and event flow

    main

    Commands act as the message channel between the UI and the host.

    • Command Dispatch: Use executeCommand("cline.xxx", ...) within your ClineButtonProvider to trigger actions.
    • Command Naming: Commands typically follow a pattern like cline.<action>. Common examples include cline.plusButtonClicked, cline.mcpButtonClicked, and cline.settingsButtonClicked.
    • Backend Requirement: Ensure your backend command dispatcher is registered to handle these cline.* commands and that the frontend WebView can receive and render the responses.
  3. How RunVSAgent architecture works

    main

    RunVSAgent enables VSCode-based coding agents to run within JetBrains IDEs by bridging the two environments. The architecture consists of three main layers:

    1. JetBrains Plugin (Kotlin): Handles IDE integration, UI components, and the Editor Bridge.
    2. Extension Host (Node.js): A runtime environment that provides a VSCode API compatibility layer and manages agents.
    3. VSCode Agents: The actual coding agents (like Roo Code, Cline, or Kilo Code) that run on top of the VSCode API layer.

    Communication between the JetBrains Plugin and the Extension Host is handled via high-performance RPC Communication (over Unix Domain Sockets or Named Pipes).

  4. Handle WebView availability for frontend actions

    main

    When performing actions that require frontend rendering (like clicking a 'New Task' button), always check for WebView availability using WebViewManager to avoid blank screens or no-op actions.

    Implementation Pattern:

    1. Obtain the manager: val webViewManager = project.getService(WebViewManager::class.java).
    2. Check availability: Use webViewManager.getLatestWebView().
    3. If unavailable:
      • Log a warning.
      • Show a user-friendly dialog (e.g., "WebView Not Available") guiding the user to initialize the panel or log in.
  5. How the RunVSAgent extension system works

    main

    RunVSAgent uses a modular, decoupled extension system that allows users to switch between different AI coding assistants (like Roo Code, Cline, etc.) without being tied to a single implementation.

    Extensions are managed via an ExtensionProvider which defines how an extension is identified, initialized, and configured. The system looks for extension files in specific directories relative to the project root, as defined by the provider's ExtensionConfiguration.

  6. How the RunVSAgent extension architecture works

    main

    The extension system follows a layered architecture to integrate AI agents (like Cline) into the IDE:

    1. Extension Provider Layer: Implements the ExtensionProvider contract. This is where the specific agent (e.g., Cline) defines its identity, initialization logic, availability checks, and metadata.
    2. Global Extension Management Layer: Managed by extensions/core/ExtensionManager. It acts as a central service for registering, selecting, and switching between different extension providers, while coordinating UI updates and configuration.
    3. UI Dynamic Adaptation Layer: Uses DynamicButtonManager and DynamicContextMenuManager to generate buttons and context menus based on the currently active provider. Providers implement ClineButtonProvider and ClineContextMenuProvider to define their specific UI elements.
    4. Command/Event Interaction Layer: UI entries trigger commands via executeCommand("cline.xxx", ...) to interact with the host. Core actions are dispatched to backend logic.
    5. WebView Capability Layer: Uses WebViewManager to host the agent's frontend interface. Certain actions (like 'New Task') perform availability checks on the WebViewManager before execution.
    graph TD
        subgraph UI[UI 层]
            BTN[Toolbar Buttons<br/>ClineButtonProvider]
            MENU[Context Menu<br/>ClineContextMenuProvider]
        end
    
        subgraph Actions[命令分发]
            EXEC[executeCommand cline commands<br/>actions package]
        end
    
        subgraph ProjectSvc[项目级扩展管理]
            EM[extensions/core/ExtensionManager]
            DBM[DynamicButtonManager]
            DCM[DynamicContextMenuManager]
        end
    
        subgraph Provider[扩展提供方]
            CLP[ClineExtensionProvider<br/>initialize/isAvailable/getConfiguration]
        end
    
        subgraph Core[核心扩展系统(VSCode 兼容层)]
            CEM[core/ExtensionManager<br/>register/activate]
            RPC[JSON-RPC / IPC]
            EXTH[ExtHostExtensionService.activate]
        end
    
        subgraph WebView[WebView 能力]
            WVM[WebViewManager]
            WV[WebView Instances]
        end
    
        BTN -->|Plus 点击前检查| WVM
        WVM -->|has latest WebView?| WV
        WV -->|是| EXEC
        WVM -. 无/空 .-> BTN
    
        MENU --> EXEC
        EXEC --> EM
        EM -->|setCurrentProvider/initialize| CLP
        EM --> DBM
        EM --> DCM
    
        CLP -->|getConfiguration| CEM
        CEM -->|register/activate| RPC --> EXTH
    
        EXEC -->|界面联动| WVM --> WV
  7. Install RunVSAgent via JetBrains Marketplace

    main

    The recommended way to install RunVSAgent is through the JetBrains Marketplace. This method is the most convenient and secure.

    1. Open your JetBrains IDE (IntelliJ IDEA, WebStorm, PyCharm, etc.).
    2. Navigate to Settings/PreferencesPlugins.
    3. Select the Marketplace tab.
    4. Search for "RunVSAgent".
    5. Click Install.
    6. Restart your IDE when prompted.

    To verify, check your IDE's plugin list after restarting to ensure RunVSAgent is present.

  8. Implement the Cline extension provider requirements

    main

    To integrate an agent like Cline, you must implement three core provider classes:

    1. ClineExtensionProvider: Defines the extension's identity (getExtensionId(), getDisplayName(), getDescription()), manages its lifecycle (initialize(project), dispose()), checks for its presence (isAvailable(project)), and provides metadata via getConfiguration(project).
    2. ClineButtonProvider: Defines the set of toolbar buttons (e.g., Plus, History, Account, Settings, MCP). When a button is clicked, it dispatches a command (e.g., cline.plusButtonClicked). Note that the 'Plus' button typically checks WebViewManager availability before executing.
    3. ClineContextMenuProvider: Defines which context menu actions are visible using isActionVisible(actionType).

    Additionally, ensure that:

    • extensions/core/ExtensionManager is used to register the provider.
    • Commands (e.g., cline.*) are registered in the com.sina.weibo.agent.actions center and align with the frontend WebView.
    • The extension's package.json and main entry point are correctly located in the user directory or plugin resources to satisfy isAvailable checks.
    // Example implementation of ClineExtensionProvider
    class ClineExtensionProvider : ExtensionProvider {
        
        override fun getExtensionId(): String = "cline"
        
        override fun getDisplayName(): String = "Cline AI"
        
        override fun getDescription(): String = "AI-powered coding assistant with advanced features"
        
        override fun initialize(project: Project) {
            // Initialize cline extension configuration
            val extensionConfig = ExtensionConfiguration.getInstance(project)
            extensionConfig.initialize()
            
            // Initialize extension manager factory if needed
            try {
                val extensionManagerFactory = ExtensionManagerFactory.getInstance(project)
                extensionManagerFactory.initialize()
            } catch (e: Exception) {
                // If ExtensionManagerFactory is not available, continue without it
            }
        }
    }
  9. Run RunVSAgent in development mode

    main

    For developers working on the project, you can run the components in development mode separately.

    Start the Extension Host (Node.js):

    cd extension_host
    npm install
    npm run dev

    Run the JetBrains Plugin (Kotlin):

    cd jetbrains_plugin
    ./gradlew runIde
    # Start extension host in development mode
    cd extension_host
    npm install
    npm run dev
    
    # Run JetBrains plugin in development mode
    cd jetbrains_plugin
    ./gradlew runIde
  10. Step-by-step guide to integrating Cline

    main

    Follow these steps to integrate a new extension like Cline:

    1. Implement Provider: Create a class implementing ClineExtensionProvider in extensions/plugin/cline/. Ensure getExtensionId() returns "cline" and implement initialize, isAvailable, getConfiguration, and dispose.
    2. Register Provider: Add your provider to the ExtensionManager.getAllExtensions() list.
    3. UI Integration: Define buttons in ClineButtonProvider and visibility in ClineContextMenuProvider.
    4. Command Dispatch: Register cline.* command handlers in the backend and ensure the WebView can respond.
    5. Prepare Files: Place extension files (including package.json) in ${VsixManager.getBaseDirectory()}/${config.codeDir}.
    6. Metadata Configuration: Verify ExtensionConfiguration.getConfig(ExtensionType.CLINE) matches your actual codeDir, publisher, version, and mainFile.
    7. Initialization: Call ExtensionManager.initialize() on startup and use setCurrentProvider("cline") to switch to it.
    8. Self-Test: Verify button clicks, command dispatch, and WebView rendering.
  11. Configure the RunVSAgent extension via .vscode-agent file

    main

    Users can specify which AI coding assistant extension to use by creating a .vscode-agent file in the project root. This file uses a properties format.

    Supported values for extension.type are:

    • roo-code (Default)
    • cline
    • kilo-code
    • costrict

    You can also configure debug modes and extension-specific settings (like API endpoints or auth tokens) within this same file.

    # Extension type to use
    extension.type=roo-code
    
    # Debug mode
    debug.mode=idea
    debug.resource=/path/to/debug/resources
    
    # Extension-specific settings
    roo.debug.enabled=false
    roo.api.endpoint=https://api.roo-code.com
    
    copilot.auth.token=your_github_token
    copilot.auto_suggest=true
    
    claude.api.key=your_anthropic_api_key
    claude.model=claude-3-sonnet-20240229
  12. Build RunVSAgent from source

    main

    To build the project, you must first initialize the development environment. The build process produces both VSCode extensions and IntelliJ IDEA plugins.

    Linux/macOS

    1. Initialize environment: ./scripts/setup.sh
    2. Build project: ./scripts/build.sh

    Windows

    1. Initialize environment: .\scripts\run.ps1 setup
    2. Build project: .\scripts\run.ps1 build

    Build Options

    • Build specific component: Use idea to build only the IntelliJ IDEA plugin.
    • Build mode: Use --mode debug for development builds with debug symbols and source maps. The default is release mode (optimized for production).
    • Custom output: Use --output <path> to specify a custom directory for artifacts.
    # First time setup
    ./scripts/setup.sh --verbose
    
    # Build in debug mode
    ./scripts/build.sh --mode debug
    
    # Build specific component (IDEA plugin)
    ./scripts/build.sh idea
    
    # Build with custom output directory
    ./scripts/build.sh --output ./dist