Mountain/IPC/mod.rs
1//! # IPC Module
2//!
3//! ## RESPONSIBILITIES
4
5#![allow(unused_imports, unused_variables)]
6//! Inter-process communication (IPC) for the Mountain application, handling
7//! communication between the Tauri frontend and the Rust backend through
8//! various protocols including Tauri commands, WebSocket, and custom message
9//! formats.
10//!
11//! ### Core Functions:
12//! - **Message Routing**: Route IPC messages to appropriate handlers
13//! - **Connection Management**: Manage IPC connections with health monitoring
14//! - **Security**: Implement permission system for IPC access control
15//! - **Encryption**: Provide secure message channels and compression
16//! - **Status Reporting**: Report IPC system status and metrics
17//! - **Configuration Bridge**: Bridge configuration across IPC boundaries
18//! - **Wind Sync**: Advanced synchronization with Wind UI framework
19//! - **Advanced Features**: Experimental/advanced IPC features
20//!
21//! ## Architectural Role
22//!
23//! The IPC module is the **communication layer** in Mountain's architecture:
24//!
25//! ```text
26//! Sky (Frontend) ──► IPC (Communication) ──► Track (Dispatch) ──► Services
27//! Wind (UI) ───────────────────────────────────────────────────────────────┘
28//! Cocoon (Sidecar) ──► Vine (gRPC) ────────────────────────────┘
29//! ```
30//!
31//! ### Design Principles:
32//! 1. **Protocol Agnostic**: Support multiple IPC protocols
33//! 2. **Security First**: All communications are secured and permission-gated
34//! 3. **High Performance**: Optimized for low-latency communication
35//! 4. **Observable**: Comprehensive logging and metrics
36//!
37//! ## Key Components
38//!
39//! - **TauriIPCServer**: Main IPC server orchestrator
40//! - **Message**: Message types and routing
41//! - **Connection**: Connection management and health
42//! - **Encryption**: Message compression and secure channels
43//! - **Security**: Permission system
44//! - **ConfigurationBridge**: Configuration synchronization
45//! - **StatusReporter**: Status and metrics reporting
46//! - **WindAdvancedSync**: Wind framework integration
47//! - **AdvancedFeatures**: Advanced/experimental features
48//!
49//! ## TODOs
50//! High Priority:
51//! - [ ] Add comprehensive unit tests for all modules
52//! - [ ] Implement connection pooling optimizations
53//! - [ ] Add connection timeout handling
54//!
55//! Medium Priority:
56//! - [ ] Add message batching for efficiency
57//! - [ ] Implement keep-alive packets
58//! - [ ] Add connection retry logic
59//!
60//! Low Priority:
61//! - [ ] Add message persistence for offline mode
62//! - [ ] Implement message compression ratio optimization
63//! - [ ] Add connection encryption rotation
64
65// --- Main Sub-modules ---
66
67/// Common shared types and abstractions for IPC layer.
68pub mod Common;
69
70/// Main Tauri IPC server orchestrator.
71// Legacy TauriIPCServer.rs for backward compatibility
72#[path = "TauriIPCServer.rs"]
73pub mod TauriIPCServer_Old;
74
75/// Message types and routing.
76pub mod Message;
77
78/// Connection management and health monitoring.
79pub mod Connection;
80
81/// Message compression and secure channels.
82pub mod Encryption;
83
84/// Permission system for IPC access control.
85pub mod Security;
86
87// --- Feature Sub-modules ---
88
89/// Advanced experimental features (collaboration, intelligent caching,
90/// performance monitoring). TODO: atomize this 648-LOC single file into a
91/// directory; for now consumers spell `IPC::AdvancedFeatures::*` directly.
92pub mod AdvancedFeatures;
93
94/// Configuration synchronization bridge.
95// Legacy ConfigurationBridge.rs for backward compatibility
96#[path = "ConfigurationBridge.rs"]
97pub mod ConfigurationBridge;
98
99/// Status and metrics reporting (atomized; siblings live in `StatusReporter/`).
100pub mod StatusReporter;
101
102/// Wind UI framework synchronization.
103// Legacy WindAdvancedSync.rs for backward compatibility
104#[path = "WindAdvancedSync.rs"]
105pub mod WindAdvancedSync;
106
107// --- Legacy Sub-modules ---
108
109/// Legacy Wind Air Commands.
110pub mod WindAirCommands;
111
112/// Legacy Wind Service Adapters.
113pub mod WindServiceAdapters;
114
115/// Tag-filtered development logging (Trace env var).
116/// Must be declared before WindServiceHandlers so the dev_log! macro is
117/// available.
118pub mod DevLog;
119
120/// Central `sky://` emit wrapper that logs under the `sky-emit` DevLog
121/// tag. Optional drop-in for any `ApplicationHandle::emit(channel, …)`
122/// call site; existing emits keep working unchanged.
123pub mod SkyEmit;
124
125/// Outbound emit wrapper that stamps a W3C `_traceparent` field onto
126/// every JSON payload before forwarding to `app_handle.emit(...)`.
127/// Sky's `Workbench/Electron/TraceparentBridge.ts` extracts the
128/// header at the receiving end so spans emitted inside the handler
129/// attach to the same Jaeger trace. Release builds short-circuit to
130/// a plain `emit(...)` via `cfg!(debug_assertions)`.
131pub mod EmitWithTraceparent;
132
133/// Shared `UriComponents` emitter. Every handler that returns a URI to the
134/// renderer must route through this module so the `$mid: 1` marshalling
135/// marker is never forgotten (without it VS Code's IPC reviver skips the
136/// field and `uri.with is not a function` cascades through the sidebar).
137pub mod UriComponents;
138
139/// Wind Service Handlers - dispatcher for every `MountainIPCInvoke` Tauri
140/// call from Wind/Output/Sky. The `mod.rs` inside is the central `match`
141/// that routes wire strings to per-domain atoms or handler files. Atoms
142/// live under `WindServiceHandlers/<Domain>/<Atom>.rs` following the
143/// one-export-per-file convention.
144///
145/// The previous `WindServiceHandler` (singular) sibling was merged here
146/// on 2026-04-23: of its 24 files, only 3 functions were live
147/// (extensions install/uninstall, nativeHost showOpenDialog) and those
148/// now live as atoms under `WindServiceHandlers/Extension/` and
149/// `WindServiceHandlers/NativeDialog/`. The remaining 21 files were
150/// dead-code duplicates of plural-side implementations.
151pub mod WindServiceHandlers;
152
153// --- Legacy Subdirectories ---
154
155/// Legacy Enhanced subdirectory.
156pub mod Enhanced;
157
158/// Legacy Permission subdirectory.
159pub mod Permission;
160
161// No `pub use` re-exports - callers spell the full path
162// (`IPC::Connection::Manager::ConnectionManager`, etc.). The legacy single-
163// file modules `TauriIPCServer_Old`, `AdvancedFeatures`, `StatusReporter`,
164// `WindAdvancedSync`, `ConfigurationBridge` remain as roots for the
165// in-progress atomic migration.
166
167// --- Notes on Migration ---
168
169// MIGRATION PATH TO ATOMIC STRUCTURE:
170//
171// Phase 1: ✅ Create Atomic Structure
172// - Created new atomic module directories
173// - Implemented core functionality
174// - Added comprehensive documentation
175//
176// Phase 2: 🔄 Backward Compatibility (Current)
177// - Keeping legacy files for compatibility
178// - Using #[path = "..."] to reference legacy files
179// - Gradually migrating dependent code
180//
181// Phase 3: ⏳ Migration
182// - Update dependent files to use new structure
183// - Test migration incrementally
184// - Monitor for issues
185//
186// Phase 4: ⏳ Cleanup
187// - Remove legacy files
188// - Update all documentation
189// - Final verification
190//
191// The following atomic modules are ready for migration:
192// - IPC/TauriIPCServer/ (Server.rs)
193// - IPC/Message/ (Types.rs)
194// - IPC/Connection/ (Manager.rs, Types.rs, Health.rs)
195// - IPC/Encryption/ (MessageCompressor.rs, SecureChannel.rs)
196// - IPC/Security/ (PermissionManager.rs, Role.rs, Permission.rs)
197// - IPC/AdvancedFeatures/ (Features.rs)
198// - IPC/ConfigurationBridge/ (mod.rs - placeholder)
199// - IPC/StatusReporter/ (mod.rs - placeholder)
200// - IPC/WindAdvancedSync/ (mod.rs - placeholder)