Skip to main content

Grove/
lib.rs

1//! Grove - Rust/WASM Extension Host for VS Code
2//!
3//! Grove provides a secure, sandboxed environment for running VS Code
4//! extensions compiled to WebAssembly or native Rust. It complements Cocoon
5//! (Node.js) by offering a native extension host with full WASM support.
6//!
7//! # Architecture
8//!
9//! ```text
10//! +++++++++++++++++++++++++++++++++++++++++++
11//! +          Extension Host                 +
12//! +++++++++++++++++++++++++++++++++++++++++++
13//! +  Extension Manager  →  Activation Engine +
14//! +  API Bridge         →  VS Code API      +
15//! +++++++++++++++++++++++++++++++++++++++++++
16//!                     +
17//! ++++++++++++++++++++▼++++++++++++++++++++++
18//! +          WASM Runtime (WASMtime)        +
19//! +  Module Loader  →  Host Bridge         +
20//! +++++++++++++++++++++++++++++++++++++++++++
21//!                     +
22//! ++++++++++++++++++++▼++++++++++++++++++++++
23//! +        Transport Layer                  +
24//! +  gRPC  |  IPC  |  Direct WASM          +
25//! +++++++++++++++++++++++++++++++++++++++++++
26//! ```
27//!
28//! # Features
29//!
30//! - **Standalone Operation**: Run independently or connect to Mountain via
31//!   gRPC
32//! - **WASM Support**: Full WebAssembly runtime with WASMtime
33//! - **Multiple Transport**: gRPC, IPC, and direct WASM communication
34//! - **Secure Sandboxing**: WASMtime-based isolation for untrusted extensions
35//! - **Cocoon Compatible**: Shares API surface with Node.js host
36//!
37//! # Example: Standalone Usage
38//!
39//! ```rust,no_run
40//! use grove::{ExtensionHost, Transport};
41//!
42//! #[tokio::main]
43//! async fn main() -> anyhow::Result<()> {
44//! 	let host = ExtensionHost::new(Transport::default()).await?;
45//! 	host.load_extension("/path/to/extension").await?;
46//! 	host.activate().await?;
47//! 	Ok(())
48//! }
49//! ```
50//!
51//! # Module Organization
52//!
53//! - [`Host`] - Extension hosting core (ExtensionHost, ExtensionManager, etc.)
54//! - [`WASM`] - WebAssembly runtime integration
55//! - [`Transport`] - Communication strategies (gRPC, IPC, WASM)
56//! - [`API`] - VS Code API facade and types
57//! - [`Protocol`] - Protocol handling (Spine connection)
58//! - [`Services`] - Host services (configuration, etc.)
59//! - [`Common`] - Shared utilities and error types
60
61#![warn(missing_docs)]
62#![deny(unsafe_code)]
63#![warn(clippy::all)]
64#![allow(non_snake_case, non_camel_case_types, unexpected_cfgs)]
65
66// Public module declarations
67pub mod API;
68pub mod Binary;
69pub mod Common;
70pub mod DevLog;
71pub mod Host;
72pub mod Protocol;
73pub mod Services;
74pub mod Transport;
75pub mod WASM;
76
77// Library version
78const VERSION:&str = env!("CARGO_PKG_VERSION");
79
80/// Grove library information
81#[derive(Debug, Clone)]
82pub struct GroveInfo {
83	/// Version string
84	pub version:&'static str,
85	/// Build timestamp
86	#[allow(dead_code)]
87	build_timestamp:String,
88}
89
90impl GroveInfo {
91	/// Create new GroveInfo with current build information
92	pub fn new() -> Self { Self { version:VERSION, build_timestamp:env!("VERGEN_BUILD_TIMESTAMP").to_string() } }
93
94	/// Get the Grove version
95	pub fn version(&self) -> &'static str { self.version }
96}
97
98impl Default for GroveInfo {
99	fn default() -> Self { Self::new() }
100}
101
102/// Initialize Grove library
103///
104/// This sets up logging and other global state.
105/// Call once at application startup.
106pub fn init() -> anyhow::Result<()> {
107	use crate::dev_log;
108	dev_log!("grove", "Grove v{} initialized", VERSION);
109
110	Ok(())
111}
112
113#[cfg(test)]
114mod tests {
115	use super::*;
116
117	#[test]
118	fn test_version() {
119		assert!(!VERSION.is_empty());
120		assert!(VERSION.contains('.'));
121	}
122
123	#[test]
124	fn test_grove_info() {
125		let info = GroveInfo::new();
126		assert_eq!(info.version(), VERSION);
127	}
128}