|
|
|
The Effect-TS native Node.js Extension Host for Landโ๐๏ธ
VS Code's extension host is a single
Node.jsevent loop. One hungPromiseblocks every other extension. There is no way to cancel an in-flight operation, no back-pressure, no preemption.
"Every extension runs in its own supervised fiber. One crash doesn't take down the rest."
@codeeditorland/cocoonโ๐ฆ
Cocoon is the Node.js/Effect-TS extension host for the
Landโ๐๏ธ Code Editor. It hosts existing VS Code extensions in a
supervised Effect-TS fiber environment, faithfully replicating the VS Code
Extension Host API. It complements Groveโ๐ณ (Rust/WASM) by
providing the Node.js hosting environment, allowing Landโ๐๏ธ to leverage
the vast VS Code extension ecosystem while adding fiber-level supervision,
structured concurrency, and resource safety.
VS Code's extension host is a single Node.js event loop - one hung Promise
blocks every other extension. Cocoon solves this by giving each extension its
own Effect-TS fiber with cancellation, back-pressure, and preemption. A crash
in one extension doesn't bring down the rest.
Cocoon is engineered to:
- Host VS Code Extensions - Run existing VS Code extensions unmodified
through a comprehensive API shim layer that mirrors
vscode.d.ts. - Provide Fiber-Level Isolation - Each extension runs in its own supervised
Effect-TSfiber with independent lifecycle, cancellation tokens, and error boundaries. - Enforce Process Hardening - Patch
process.exit, block native modules, intercept uncaught exceptions, and terminate if the parentMountainโโฐ๏ธ process exits. - Bridge via gRPC & WebSocket - Communicate with
Mountainโโฐ๏ธ throughgRPC(Vineโ๐ฟ protocol on port:50052) and withSkyโ๐ through aWebSocketJSON-RPC transport with cryptographic authentication.
Effect-TS Fiber Supervision - Every extension activation runs in its own
Effect fiber with structured concurrency. Cancellation propagates cleanly
through the fiber tree, hung operations are preemptible, and fiber crashes are
trapped at the supervision boundary rather than taking down the host process.
Full vscode API Shimming - The APIFactory service constructs a complete
vscode API object with namespaces for window, workspace, commands,
languages, debug, scm, tasks, env, extensions, authentication,
tests, and comments. Extension code runs against this shim without
modification.
Process Security Hardening - The PatchProcess module runs before any
extension activates, intercepting process.exit, process.crash, native module
loads, uncaught exceptions, and unhandled rejections. A configurable
SecurityPolicy controls exit permissions, memory limits, network access, file
system access, and child process spawning.
Code Generation Pipeline - The Codegen module scans the VS Code
extension-host source tree (Windโ๐) to discover the actual API methods
and types being used. It then generates matching TypeScript schema files that
Cocoon uses to talk to Mountainโโฐ๏ธ - no hand-written stubs,
everything is derived from the real upstream sources.
Multi-Transport Communications - gRPC (Vineโ๐ฟ protocol to
Mountainโโฐ๏ธ), WebSocket JSON-RPC (to Skyโ๐ with hex-secret
auth via URL param, Sec-WebSocket-Protocol, or X-Land-Secret header), and
IPC (buffered multi-channel RPC for local communication).
Bidirectional Streaming - The gRPC server implements the Vineโ๐ฟ
protocol with bidirectional streaming, allowing Mountainโโฐ๏ธ to push
notifications and events into Cocoon asynchronously without polling.
Telemetry & Observability - PostHog event buffering and batching with
identity management, plus OTLP fire-and-forget span export for distributed
tracing. Tree-shaken from production builds via esbuild define substitution.
Dual-Layer Debug Server - An HTTP inspection surface (:9934) matching
Mountainโโฐ๏ธ's DebugServer wire protocol, supporting /health,
/layers, /execute (eval in extension host scope), and /extensions
endpoints for runtime introspection.
| Principle | Description | Key Components |
|---|---|---|
| Fiber Isolation | Each extension is a separate Effect fiber with its own supervision tree, cancellation scope, and error channel. Failures don't cascade. |
Service/Effect/Extension.ts, Service/Effect/Bootstrap.ts, Service/Effect/Module/Interceptor.ts |
| API Surface Parity | Implement the full VS Code extension API (vscode.d.ts) so extensions port seamlessly between Cocoon and Groveโ๐ณ. |
Services/API/Factory/, Services/Handler/VscodeAPI/*, Services/Extension/Host/ |
| Defense in Depth | Process-level hardening (PatchProcess) + Effect-TS error boundaries + configurable SecurityPolicy + platform-native sandboxing (future). |
PatchProcess/Patcher.ts, PatchProcess/Security.ts, PatchProcess/Validator.ts |
| Transport Flexibility | Multiple communication channels (gRPC, WebSocket, IPC) for different deployment topologies, each behind a typed interface. |
Services/gRPC/Server/, Services/Mountain/gRPC/Client.ts, Bootstrap/WebSocket/Server.ts, IPC/Channel.ts |
Cocoon operates as a standalone Node.js process orchestrated by and
communicating with Mountainโโฐ๏ธ.
graph LR
classDef mountain fill:#f0d0ff,stroke:#9b59b6,stroke-width:2px,color:#2c0050;
classDef cocoon fill:#d0d8ff,stroke:#4a6fa5,stroke-width:2px,color:#001050;
classDef effectts fill:#d4f5d4,stroke:#27ae60,stroke-width:1px,color:#0a3a0a;
classDef vscode fill:#ebebeb,stroke:#888,stroke-width:1px,stroke-dasharray:5 5,color:#333;
classDef ipc fill:#fff3c0,stroke:#f39c12,stroke-width:1px,stroke-dasharray:5 5,color:#5a3e00;
subgraph COCOON["Cocoonโ๐ฆโ- Node.js Extension Host Sidecar"]
direction TB
subgraph BOOT["Bootstrap/ - Startup"]
PatchProcess["PatchProcess/ - Process Hardeningโ๐"]:::cocoon
MainEntry["Bootstrap/Implementation/Cocoon/Main.tsโ๐"]:::effectts
AppLayer["Service/Mapping.ts - AppLayerโ๐งฉ"]:::effectts
end
subgraph EFFECTS["Service/Effect/ - Lifecycle Orchestration"]
BootstrapEff["Service/Effect/Bootstrap.tsโโก"]:::effectts
ExtEff["Service/Effect/Extension.ts"]:::effectts
ModInterceptor["Service/Effect/Module/Interceptor.ts\n(require/import patch)"]:::effectts
end
subgraph SERVICES["Services/ - vscode API Shims"]
APIFactory["Services/API/Factory - vscode objectโ๐ญ"]:::cocoon
ExtHostSvc["Services/Extension/Host"]:::cocoon
WindowSvc["Services/Window ยท Workspace ยท Command ยท Terminal"]:::cocoon
WebviewSvc["WebviewPanel/ - Panel lifecycleโ๐"]:::cocoon
end
subgraph TRANSPORT["IPC/ + gRPC Transport"]
IPCChannel["IPC/Channel.ts - multi-channel RPCโ๐ก"]:::ipc
GRPCClient["Services/Mountain/gRPC/Client.tsโ๐ฟ"]:::ipc
GRPCServer["Services/gRPC/Server/ - Vine implโ๐"]:::ipc
end
subgraph SUPPORT["Support Modules"]
TypeConverter["TypeConverter/ - DTO serializationโ๐"]:::cocoon
Platform["Platform/ - OS/env abstractionโ๐ป"]:::cocoon
Telemetry["Telemetry/ - PostHog + OTLPโ๐"]:::cocoon
end
PatchProcess --> MainEntry
MainEntry --> AppLayer
AppLayer --> BootstrapEff
BootstrapEff --> ExtEff
BootstrapEff --> ModInterceptor
AppLayer --> SERVICES
SERVICES --> TypeConverter
APIFactory --> ExtHostSvc
ExtHostSvc --> GRPCClient
GRPCClient --> IPCChannel
GRPCServer --> IPCChannel
AppLayer -.-> Platform
AppLayer -.-> Telemetry
end
subgraph MOUNTAIN["Mountainโโฐ๏ธโ- Rust/Tauri Backend"]
VineGRPC["Vine gRPC Serverโ๐ฟ"]:::mountain
end
subgraph EXT["VS Code Extensionsโ๐ฆ"]
ExtCode["Extension Codeโ๐"]:::vscode
end
APIFactory -- injects vscode API --> ExtCode
ExtCode -- API calls --> SERVICES
GRPCClient <-- gRPC :50052 --> VineGRPC
GRPCServer <-- notifications --> VineGRPC
| Component | Path | Description |
|---|---|---|
| Main Entry | Source/Bootstrap/Implementation/Cocoon/Main.ts |
Primary entry point composing all Effect-TS layers, establishing gRPC connection, handshake with Mountainโโฐ๏ธ |
| Bootstrap | Source/Service/Effect/Bootstrap.ts |
Lean async bootstrap orchestrating initialization stages: environment detection, configuration, gRPC connection, module interceptor, extension registry, health checks |
| Service Mapping | Source/Service/Mapping.ts |
Dependency injection container wiring all services into the main AppLayer |
| APIFactory | Source/Services/API/Factory/Service.ts |
Constructs the vscode API object that extensions receive |
| Extension Host | Source/Services/Extension/Host/Service.ts |
Manages extension activation and lifecycle with module interception and API injection |
| IPC Channel | Source/IPC/Channel.ts |
Multi-channel RPC system management with advanced message routing |
| gRPC Client | Source/Services/Mountain/gRPC/Client.ts |
Effect-TS wrapper for Mountainโโฐ๏ธ gRPC operations |
| gRPC Server | Source/Services/gRPC/Server/Service.ts |
Cocoon's gRPC server implementing the Vineโ๐ฟ protocol with bidirectional streaming |
| WebSocket Server | Source/Bootstrap/WebSocket/Server.ts |
JSON-RPC WebSocket server for Skyโ๐โCocoon direct transport with cryptographic authentication |
| PatchProcess | Source/PatchProcess/ |
Process hardening: patches process.exit, handles exceptions, enforces security policy |
| TypeConverter | Source/TypeConverter/ |
Pure functions to serialize TypeScript types into plain DTOs for gRPC transport |
| Codegen | Source/Codegen/ |
Code generation pipeline walking VS Code extension-host source to emit IExtHost*Upstream schemas |
| Platform | Source/Platform/ |
Platform abstraction layer providing OS, environment, and process info as Effect-TS service |
| WebviewPanel | Source/WebviewPanel/ |
Webview panel factory, implementation, and serializer managing lifecycle and state |
| Telemetry | Source/Telemetry/ |
PostHog and OTLP telemetry bridges with event buffering and identity management |
| Debug Server | Source/Debug/Server.ts |
HTTP inspection surface (:9934) for /health, /layers, /execute, /extensions runtime introspection |
Element/Cocoon/
โโโ Source/
โ โโโ Bootstrap/ # Startup and initialization
โ โ โโโ Implementation/Cocoon/ # Main entry point (Main.ts)
โ โ โโโ WebSocket/ # WebSocket server for Sky transport
โ โโโ Codegen/ # VS Code extension-host codegen pipeline
โ โ โโโ Emit/Emit/Ext/Host/ # Schema emission
โ โ โโโ Extract/ # Decorator extraction and file filtering
โ โ โโโ Run/Ext/Host/ # Codegen runner
โ โ โโโ Type/Ext/Host/ # Decorator record types
โ โโโ Configuration/ # ESBuild and Mountain configuration
โ โ โโโ ESBuild/ # ESBuild configs (Bootstrap, Cocoon, Target)
โ โ โโโ Mountain/ # Mountain integration config
โ โโโ Debug/ # Dual-layer HTTP inspection server
โ โโโ Integration/ # Mountain client integration
โ โโโ Interfaces/ # Service interfaces (I* pattern)
โ โ โโโ I/ # Configuration, Error, Extension, FileSystem,
โ โ IAPI/Factory/ # ModuleInterceptor, MountainClient,
โ โ IGRPC/Server/ # Performance, Security, Terminal
โ โโโ IPC/ # Multi-channel RPC system
โ โ โโโ Message/ # Message serialization, deserialization,
โ โ # batching, validation, types, VSBuffer
โ โโโ PatchProcess/ # Process hardening and security enforcement
โ โโโ Platform/ # OS, environment, logging abstraction
โ โโโ Service/ # Service wiring (AppLayer mapping)
โ โ โโโ Effect/ # Effect-TS lifecycle orchestration
โ โ โโโ Module/ # Module interceptor (require/import patches)
โ โโโ Services/ # VS Code API shim services
โ โ โโโ API/Factory/ # vscode API object construction
โ โ โโโ Extension/Host/ # Extension activation and lifecycle
โ โ โโโ Extensions/ # Extension scanner
โ โ โโโ gRPC/Server/ # Vine gRPC protocol implementation
โ โ โโโ Handler/ # API request routing and dispatch
โ โ โ โโโ VscodeAPI/ # Individual vscode namespace handlers:
โ โ โ Authentication/, Commands/, Comments/, Debug/, Env/,
โ โ โ Extensions/, Languages/, Scm/, Tasks/, Tests/,
โ โ โ Window/, Workspace/
โ โ โโโ Mountain/gRPC/ # gRPC client for Mountain communication
โ โ โโโ Window/ # Window service (dialogs, output, status bar,
โ โ # webview panels, terminals, text documents)
โ โโโ Telemetry/ # PostHog + OTLP telemetry bridges
โ โโโ TypeConverter/ # DTO serialization for gRPC transport
โ โโโ Utility/ # Shared utilities (events, globs, logging)
โ โโโ WebviewPanel/ # Webview panel lifecycle management
โโโ Scripts/ # Build and codegen scripts
โโโ compile-grpc-protocol.js # gRPC protocol compilation
Cocoon operates as a standalone Node.js process orchestrated by
Mountainโโฐ๏ธ. It provides the Node.js extension runtime environment
that allows existing VS Code extensions to run unmodified within Landโ๐๏ธ.
It complements Groveโ๐ณ (Rust/WASM) as the second extension host,
together providing the two execution environments for Land's extension model:
| Host | Language | Runtime | Isolation |
|---|---|---|---|
| Cocoonโ๐ฆ | TypeScript, JavaScript |
Node.js via Effect-TS |
Fiber-level supervision + process hardening |
| Groveโ๐ณ | Rust, WASM |
WASMtime |
Hardware-enforced via capability model |
- Depends on:
Mountainโโฐ๏ธ (gRPC host),@codeeditorland/output(VS Code platform code),Windโ๐ (extraction pipeline for codegen) - Consumed by: VS Code extensions running in Landโ๐๏ธ
- Protocol:
gRPC(Vineโ๐ฟ protocol on port:50052),WebSocket(JSON-RPCwith cryptographic auth toSkyโ๐)
Mountainโโฐ๏ธ launches Cocoon with initialization data.- Cocoon's
Main.tsbootstraps:PatchProcesshardens the environment,Effect/Bootstrap.tsorchestrates initialization (environment detection, configuration,gRPCconnection, module interceptor, extension registry, health checks), andService/Mapping.tsbuilds the mainAppLayer. ExtHostExtensionServiceactivates an extension, which receives avscodeAPI object fromAPIFactory.- The extension calls
vscode.window.showInformationMessage("Hello"). - The call is routed to the
Windowservice, which creates anEffectsending ashowMessagegRPCrequest toMountainโโฐ๏ธ. Mountainโโฐ๏ธ'sVineโ๐ฟ layer receives the request and dispatches it to the native UI handler.Mountainโโฐ๏ธ displays the native OS notification and awaits interaction.- The result flows back via
gRPCresponse, completing theEffectand resolving the extension'sPromise.
- Node.js v18 or later
- pnpm (monorepo package manager)
Cocoon is developed as a core component of the Land project. It is built
as part of the monorepo and requires the Bundle=true build variable, which
triggers the Restโโฑ๏ธ element to prepare the necessary VS Code platform
code.
| Package | Purpose |
|---|---|
effect (v3.21.3) |
Core library for the entire application structure |
@effect/platform (v0.96.1) |
Effect-TS platform abstractions |
@effect/platform-node (v0.107.0) |
Node.js-specific Effect-TS platform |
@grpc/grpc-js (v1.14.4) |
gRPC communication |
@grpc/proto-loader (v0.8.1) |
.proto file loading for gRPC |
@codeeditorland/output (v0.0.1) |
Compiled VS Code platform code from Land/Dependency |
google-protobuf & protobufjs |
Protocol buffers for gRPC |
Debugging Cocoon: Attach a standard Node.js debugger. Mountainโโฐ๏ธ
must launch Cocoon with debug flags (e.g., --inspect-brk=PORT_NUMBER). Logs
from Cocoon are automatically piped to Mountainโโฐ๏ธ's console via the
PatchProcess module.
Cocoon enforces security at multiple layers:
| Layer | Mechanism |
|---|---|
| Process Hardening | PatchProcess/Patcher.ts runs before any extension: blocks process.crash(), intercepts process.exit() (unless SecurityPolicy.AllowExit), blocks native module loads (Module._load("natives")), sets Error.stackTraceLimit=100 |
| Exception Boundaries | uncaughtException and unhandledRejection handlers trap orphaned errors to stderr; gRPC RPC takes over error forwarding once connected |
| Parent Liveness | TerminateOnParentExit monitors VSCODE_PID and exits cleanly if the parent Mountainโโฐ๏ธ process dies |
| SecurityPolicy | Configurable policy controlling exit permissions, memory limits (MaxMemoryMB), network access (AllowNetwork), child process spawning (AllowChildProcesses), file system access validation, and environment variable restrictions |
| Runtime Validation | Validator service runs continuous security validation: file system access checks, network access checks, memory usage monitoring, suspicious behavior detection, and audit trail generation |
| Module Interception | Module/Interceptor patches require/import to control which modules extensions can load; the vscode API object is injected through this interceptor |
| WebSocket Auth | Cryptographic authentication via timingSafeEqual hex secret comparison: accepted through URL ?secret=, Sec-WebSocket-Protocol header, or X-Land-Secret header |
| Memory Enforcement | Soft memory limit using v8.setFlagsFromString("--max-old-space-size=โฆ"); configurable per-extension via SecurityPolicy.MaxMemoryMB |
Future platform-native layers: Windows Job Objects / AppContainer, Linux
seccomp via libseccomp, and macOS sandbox via sandbox-exec.
Cocoon is designed to be compatible with:
| Target | Integration |
|---|---|
| Groveโ๐ณ | Shares VS Code API surface, activation semantics, and manifest parsing for seamless extension porting |
| VS Code | Implements vscode.d.ts type definitions; existing extensions run unmodified |
| Mountainโโฐ๏ธ | Integrates via gRPC using the Vineโ๐ฟ protocol on port :50052 with bidirectional streaming |
| Skyโ๐ | Direct WebSocket JSON-RPC transport with cryptographic authentication |
| Outputโโซ | Consumes compiled VS Code platform code from @codeeditorland/output |
- Main Entry Point
- Application bootstrap and layer composition
- Effect Services
- Lifecycle orchestration (
Bootstrap.ts,Extension.ts,Module/Interceptor.ts)
- Lifecycle orchestration (
- Service Mapping
- Dependency injection container and
AppLayer
- Dependency injection container and
- gRPC Client
Mountainโโฐ๏ธgRPCclient operations
- gRPC Server
Vineโ๐ฟ protocol server with bidirectional streaming
- WebSocket Server
JSON-RPCWebSocketserver forSkyโ๐ transport
- TypeConverter
- DTO serialization for
gRPCtransport
- DTO serialization for
- Architecture Overview - Internal module structure
- Why Effect-TS - Design rationale for
Effect-TS - Why gRPC - Design rationale for
gRPC - Land Documentation - Complete documentation index
- Windโ๐ - Service layer (correlated frontend element)
- Workerโ๐ฉ - Service worker for caching and offline support
- Vineโ๐ฟ -
gRPCprotocol definition - Groveโ๐ณ -
Rust/WASMextension host - Mountainโโฐ๏ธ - Native
desktop shell and
gRPCbackend
This project is released into the public domain under the Creative Commons CC0
Universal license. You are free to use, modify, distribute, and build upon
this work for any purpose, without any restrictions. For the full legal text,
see the LICENSE
file.
Stay updated with our progress! See
CHANGELOG.md
for a history of changes.
Landโ๐๏ธ is proud to be an open-source endeavor. Our journey is significantly supported by the organizations and projects that believe in the future of open-source software.
This project is funded through NGI0 Commons Fund, a fund established by NLnet with financial support from the European Commission's Next Generation Internet program. Learn more at the NLnet project page.
| Land | PlayForm | NLnet | NGI0 Commons Fund |
|---|---|---|---|
|
|
|
|
|
Project Maintainers: Source Open (Source/Open@editor.land) | GitHub Repository | Report an Issue | Security Policy