LaunchAndManageCocoonSideCar

Function LaunchAndManageCocoonSideCar 

Source
async fn LaunchAndManageCocoonSideCar(
    ApplicationHandle: AppHandle,
    Environment: Arc<MountainEnvironment>,
) -> Result<(), CommonError>
Expand description

Spawns the Cocoon process, manages its communication channels, and performs the complete initialization handshake sequence.

This function implements the complete Cocoon lifecycle:

  1. Validates bootstrap script availability
  2. Constructs environment variables for IPC and logging
  3. Spawns Node.js process with proper IO redirection
  4. Captures stdout/stderr for logging
  5. Waits for gRPC server to be ready
  6. Establishes Vine connection
  7. Sends initialization payload and validates response

§Arguments

  • ApplicationHandle - Tauri application handle for resolving resource paths
  • Environment - Mountain environment containing application state

§Returns

  • Ok(()) - Cocoon process spawned, connected, and initialized successfully
  • Err(CommonError) - Any failure during the initialization sequence

§Errors

  • FileSystemNotFound: Bootstrap script not found in resources
  • IPCError: Failed to spawn process, connect gRPC, or complete handshake

§Lifecycle

The process runs as a background task with IO redirection for logging. Process failures are logged but not automatically restarted (callers should implement restart strategies based on their requirements).