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 Host;
71pub mod Protocol;
72pub mod Services;
73pub mod Transport;
74pub mod WASM;
75
76// Re-exports for convenience
77pub use API::{types, vscode};
78pub use Binary::Build::{RuntimeBuild, ServiceRegister};
79pub use Binary::Main::Entry::{Entry, ValidationResult, BuildResult, ExtensionInfo};
80pub use Common::{
81	error::{GroveError, GroveResult},
82	traits::ExtensionContext,
83};
84// Transport module exports are already re-exported in Transport/mod.rs
85// Use grove::Transport::{Transport, TransportType, TransportStats, GrpcTransport, IPCTransportImpl, WASMTransportImpl}
86pub use WASM::Runtime;
87// Note: ExtensionHost, ExtensionManager must be accessed via module prefix
88
89// Library version
90const VERSION:&str = env!("CARGO_PKG_VERSION");
91
92/// Grove library information
93#[derive(Debug, Clone)]
94pub struct GroveInfo {
95	/// Version string
96	pub version:&'static str,
97	/// Build timestamp
98	build_timestamp:String,
99}
100
101impl GroveInfo {
102	/// Create new GroveInfo with current build information
103	pub fn new() -> Self { Self { version:VERSION, build_timestamp:env!("VERGEN_BUILD_TIMESTAMP").to_string() } }
104
105	/// Get the Grove version
106	pub fn version(&self) -> &'static str { self.version }
107}
108
109impl Default for GroveInfo {
110	fn default() -> Self { Self::new() }
111}
112
113/// Initialize Grove library
114///
115/// This sets up logging and other global state.
116/// Call once at application startup.
117pub fn init() -> anyhow::Result<()> {
118	// Initialize tracing subscriber with environment-based filtering
119	let filter = tracing_subscriber::EnvFilter::from_default_env().add_directive(tracing::Level::INFO.into());
120
121	tracing_subscriber::fmt()
122		.with_env_filter(filter)
123		.with_target(false)
124		.try_init()
125		.map_err(|e| anyhow::anyhow!("Failed to initialize tracing: {}", e))?;
126
127	tracing::info!("Grove v{} initialized", VERSION);
128
129	Ok(())
130}
131
132#[cfg(test)]
133mod tests {
134	use super::*;
135
136	#[test]
137	fn test_version() {
138		assert!(!VERSION.is_empty());
139		assert!(VERSION.contains('.'));
140	}
141
142	#[test]
143	fn test_grove_info() {
144		let info = GroveInfo::new();
145		assert_eq!(info.version(), VERSION);
146	}
147}