Expand description
§Cocoon Management
This module provides comprehensive lifecycle management for the Cocoon sidecar process, which serves as the VS Code extension host within the Mountain editor.
§Overview
Cocoon is a Node.js-based process that provides compatibility with VS Code extensions. This module handles:
- Process Spawning: Launching Node.js with the Cocoon bootstrap script
- Environment Configuration: Setting up environment variables for IPC and logging
- Communication Setup: Establishing gRPC/Vine connections on port 50052
- Health Monitoring: Tracking process state and handling failures
- Lifecycle Management: Graceful shutdown and restart capabilities
- IO Redirection: Capturing stdout/stderr for logging and debugging
§Process Communication
The Cocoon process communicates via:
- gRPC on port 50052 (configured via MOUNTAIN_GRPC_PORT/COCOON_GRPC_PORT)
- Vine protocol for cross-process messaging
- Standard streams for logging (VSCODE_PIPE_LOGGING)
§Dependencies
scripts/cocoon/bootstrap-fork.js: Bootstrap script for launching Cocoon- Node.js runtime: Required for executing Cocoon
- Vine gRPC server: Must be running on port 50051 for handshake
§Error Handling
The module provides graceful degradation:
- If the bootstrap script is missing, returns
FileSystemNotFounderror - If Node.js cannot be spawned, returns
IPCError - If gRPC connection fails, returns
IPCErrorwith context
§Module Contents
InitializeCocoon: Main entry point for Cocoon initializationLaunchAndManageCocoonSideCar: Process spawning and lifecycle management
§Example
use crate::Source::ProcessManagement::CocoonManagement::InitializeCocoon;
// Initialize Cocoon with application handle and environment
match InitializeCocoon(&app_handle, &environment).await {
Ok(()) => println!("Cocoon initialized successfully"),
Err(e) => eprintln!("Cocoon initialization failed: {:?}", e),
}Structs§
- COCOON_
HEALTH 🔒 - COCOON_
STATE 🔒 - Cocoon
Process 🔒State - Global state for tracking Cocoon process lifecycle
Constants§
- BOOTSTRAP_
SCRIPT_ 🔒PATH - COCOON_
GRPC_ 🔒PORT - COCOON_
SIDE_ 🔒CAR_ IDENTIFIER - Configuration constants for Cocoon process management
- GRPC_
SERVER_ 🔒READY_ DELAY_ MS - HANDSHAKE_
TIMEOUT_ 🔒MS - HEALTH_
CHECK_ 🔒INTERVAL_ SECONDS - MAX_
RESTART_ 🔒ATTEMPTS - MOUNTAIN_
GRPC_ 🔒PORT - RESTART_
WINDOW_ 🔒SECONDS
Functions§
- Initialize
Cocoon - The main entry point for initializing the Cocoon sidecar process manager.
- Launch
AndManage 🔒Cocoon Side Car - Spawns the Cocoon process, manages its communication channels, and performs the complete initialization handshake sequence.
- monitor_
cocoon_ 🔒health_ task - Background task that monitors Cocoon process health and logs crashes