Skip to main content

Deep Dive

Grove - Deep Dive

Deep dive into Grove, the native, sandboxed Rust/WASM extension host that provides an environment for running VS Code extensions compiled to WebAssembly or native Rust, complementing the Node.js-based Cocoon host.

Grove - Deep Dive

Grove provides the technical foundation Rust/WASM extension host within the Land project. Grove provides a native, sandboxed environment for running VS Code extensions compiled to WebAssembly or native Rust, complementing the Node.js-based Cocoon host.


Architecture

Grove is organized into five layers: the extension host controller that manages the lifecycle, the WASM runtime that provides sandboxed execution, the VS Code API bridge that presents the standard extension API, the transport layer that communicates with Mountain, and shared utility modules.

graph TB
    subgraph "Grove - Rust/WASM Extension Host"
        Main["main.rs / lib.rs<br/>Binary + Library entry"]
        Binary["Binary/<br/>CLI and startup"]
        Host["Host/<br/>Extension Host Controller"]
        ExtHost["Host/ExtensionHost.rs<br/>Main controller"]
        ExtMgr["Host/ExtensionManager.rs<br/>Discovery and loading"]
        Activation["Host/Activation.rs<br/>Activation events"]
        Lifecycle["Host/Lifecycle.rs<br/>Extension lifecycle"]
        APIBridge["Host/APIBridge.rs<br/>VS Code API facade"]
        WASM["WASM/<br/>WebAssembly Runtime"]
        Runtime["WASM/Runtime.rs<br/>WASMtime engine + store"]
        ModuleLoader["WASM/ModuleLoader.rs<br/>Module compilation"]
        MemoryMgr["WASM/MemoryManager.rs<br/>Memory allocation"]
        HostBridge["WASM/HostBridge.rs<br/>Host-WASM function bridge"]
        Transport["Transport/<br/>Communication Strategies"]
        GRPCTransport["Transport/gRPCTransport.rs<br/>gRPC via Mountain"]
        IPCTransport["Transport/IPCTransport.rs<br/>Local IPC"]
        WASMTransport["Transport/WASMTransport.rs<br/>Direct WASM calls"]
        Protocol["Protocol/<br/>Spine connection"]
    end

    subgraph "Mountain - Rust Backend"
        VineGRPC["Vine gRPC Server"]
    end

    Main --> Binary
    Binary --> Host
    Host --> ExtHost
    ExtHost --> ExtMgr
    ExtHost --> Activation
    ExtHost --> Lifecycle
    ExtHost --> APIBridge
    APIBridge --> WASM
    WASM --> Runtime
    WASM --> ModuleLoader
    WASM --> MemoryMgr
    WASM --> HostBridge
    ExtHost --> Transport
    Transport --> GRPCTransport
    Transport --> IPCTransport
    Transport --> WASMTransport
    ExtHost --> Protocol
    GRPCTransport --> VineGRPC

Key Modules

PathDescription
Source/lib.rsLibrary root; exports public API for integration and testing
Source/main.rsBinary entry point; parses CLI and starts the extension host
Source/Binary/CLI argument handling and standalone vs connected mode selection
Source/Host/ExtensionHost.rsMain controller: coordinates extension loading, activation, and service provision
Source/Host/ExtensionManager.rsExtension discovery, manifest parsing, and loading
Source/Host/Activation.rsActivation event processing (onLanguage, onCommand, etc.)
Source/Host/Lifecycle.rsExtension activate/deactivate lifecycle management
Source/Host/APIBridge.rsVS Code API facade implementation for Rust/WASM extensions
Source/WASM/Runtime.rsWASMtime engine and store management with memory limits
Source/WASM/ModuleLoader.rsWASM module compilation, caching, and instantiation
Source/WASM/MemoryManager.rsWASM linear memory allocation and bounds enforcement
Source/WASM/HostBridge.rsHost function exports to WASM modules
Source/WASM/FunctionExport.rsRegistered host functions available to extension WASM code
Source/Transport/Strategy.rsTransport strategy trait for pluggable communication
Source/Transport/gRPCTransport.rsgRPC communication with Mountain via tonic
Source/Transport/IPCTransport.rsUnix/Windows IPC transport for same-host communication
Source/Transport/WASMTransport.rsDirect in-process WASM function call transport
Source/Protocol/SpineConnection.rsSpine protocol client for extension host coordination

Data Flow

sequenceDiagram
    participant Mountain as Mountain Core
    participant Grove as Grove Extension Host
    participant WASM as WASM Runtime
    participant Extension as WASM Extension

    Mountain->>Grove: GroveService.ActivateExtension (gRPC via Vine)
    Grove->>Grove: ExtensionManager.load(manifest)
    Grove->>WASM: ModuleLoader.compile(wasm_bytes)
    WASM->>Grove: Compiled module
    Grove->>WASM: Runtime.instantiate(module, host_functions)
    WASM->>Extension: WASM module initialized
    Extension->>WASM: Call host function (e.g. vscode.workspace.readFile)
    WASM->>Grove: HostBridge dispatch
    Grove->>Mountain: Forward service call via Transport
    Mountain->>Grove: Service result
    Grove->>WASM: Return value to extension
    WASM->>Extension: Result available

Integration Points

Connecting ElementDirectionMechanismDescription
MountainBidirectionalgRPC via VineMountain activates extensions; Grove forwards API calls back to Mountain
CocoonSiblingShared API surfaceGrove implements the same VS Code API surface as Cocoon for extension portability

Configuration

OptionCLI Flag / FeatureDefaultDescription
Standalone mode--standaloneoffRun without Mountain connection for testing
Extension path--extensionunsetLoad a specific extension directly
Transportfeature flaggRPCSelect grpc, ipc, or wasm transport via Cargo features
Memory limitruntime configplatform defaultPer-extension WASM memory ceiling enforced by WASMtime
WASM build targetwasm32-wasinativeExtensions must target wasm32-wasi for WASM mode

Cargo features

FeatureDescription
grpcgRPC transport support (included in default)
wasmWASMtime WASM runtime (included in default)
ipcUnix/Windows IPC transport (Unix only)
allAll features enabled