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;
68
69pub mod Binary;
70
71pub mod Common;
72
73pub mod DevLog;
74
75pub mod Host;
76
77pub mod Protocol;
78
79pub mod Services;
80
81pub mod Transport;
82
83pub mod WASM;
84
85// Library version
86const VERSION:&str = env!("CARGO_PKG_VERSION");
87
88/// Grove library information
89#[derive(Debug, Clone)]
90pub struct GroveInfo {
91	/// Version string
92	pub version:&'static str,
93
94	/// Build timestamp
95	#[allow(dead_code)]
96	build_timestamp:String,
97}
98
99impl GroveInfo {
100	/// Create new GroveInfo with current build information
101	pub fn new() -> Self { Self { version:VERSION, build_timestamp:env!("VERGEN_BUILD_TIMESTAMP").to_string() } }
102
103	/// Get the Grove version
104	pub fn version(&self) -> &'static str { self.version }
105}
106
107impl Default for GroveInfo {
108	fn default() -> Self { Self::new() }
109}
110
111/// Initialize Grove library
112///
113/// This sets up logging and other global state.
114/// Call once at application startup.
115pub fn init() -> anyhow::Result<()> {
116	use crate::dev_log;
117
118	dev_log!("grove", "Grove v{} initialized", VERSION);
119
120	Ok(())
121}
122
123#[cfg(test)]
124mod tests {
125
126	use super::*;
127
128	#[test]
129	fn test_version() {
130		assert!(!VERSION.is_empty());
131
132		assert!(VERSION.contains('.'));
133	}
134
135	#[test]
136	fn test_grove_info() {
137		let info = GroveInfo::new();
138
139		assert_eq!(info.version(), VERSION);
140	}
141}