dx_forge/
lib.rs

1//! # DX Forge - Production-Ready VCS and Orchestration Engine
2//!
3//! Forge is the orchestration backbone for the DX tools ecosystem, providing:
4//! - Content-addressable storage with SHA-256 blob hashing
5//! - Git-compatible versioning with traffic branch safety system
6//! - Dual-watcher architecture (LSP + File System monitoring)
7//! - Tool orchestration with priority-based execution and dependency resolution
8//! - Component injection for zero-bloat dependency management
9//! - Semantic versioning with dependency resolution
10//! - Pattern detection for dx-tools (dxButton, dxiIcon, dxfRoboto, etc.)
11//! - R2 component caching and injection
12//! - Production error handling with retry logic
13//!
14//! ## Architecture Overview
15//!
16//! Forge eliminates node_modules bloat by detecting code patterns via LSP,
17//! injecting only needed components directly into user files, and coordinating
18//! DX tool execution with traffic branch safety logic.
19//!
20//! ### Core Components
21//!
22//! - **Orchestrator**: Coordinates tool execution with lifecycle hooks, circular dependency detection
23//! - **Dual-Watcher**: Monitors LSP + file system changes with pattern detection
24//! - **Traffic Branch System**: Green (auto), Yellow (merge), Red (manual) for safe updates
25//! - **Storage Layer**: Content-addressable blobs with R2 cloud sync
26//! - **Version Manager**: Semantic versioning with compatibility checking
27//! - **Pattern Detector**: Identifies dx-tool patterns in source code
28//! - **Injection Manager**: Fetches and caches components from R2 storage
29//!
30//! ## Quick Start - Tool Development
31//!
32//! ```rust,no_run
33//! use dx_forge::{DxTool, ExecutionContext, ToolOutput, Orchestrator};
34//! use async_trait::async_trait;
35//! use anyhow::Result;
36//!
37//! struct MyDxTool;
38//!
39//! #[async_trait]
40//! impl DxTool for MyDxTool {
41//!     fn name(&self) -> &str { "dx-mytool" }
42//!     fn version(&self) -> &str { "1.0.0" }
43//!     fn priority(&self) -> i32 { 50 }
44//!     
45//!     async fn execute(&self, ctx: &ExecutionContext) -> Result<ToolOutput> {
46//!         // Your tool logic here
47//!         Ok(ToolOutput::success("Done!"))
48//!     }
49//! }
50//!
51//! #[tokio::main]
52//! async fn main() -> Result<()> {
53//!     let mut orchestrator = Orchestrator::new(".")?;
54//!     orchestrator.register_tool(Box::new(MyDxTool));
55//!     orchestrator.execute_all().await?;
56//!     Ok(())
57//! }
58//! ```
59//!
60//! ## Quick Start - Change Detection
61//!
62//! ```rust,no_run
63//! use dx_forge::{DualWatcher, FileChange};
64//! use tokio::sync::broadcast;
65//!
66//! #[tokio::main]
67//! async fn main() -> anyhow::Result<()> {
68//!     let watcher = DualWatcher::new(".")?;
69//!     let mut rx = watcher.subscribe();
70//!     
71//!     tokio::spawn(async move {
72//!         watcher.start().await
73//!     });
74//!     
75//!     while let Ok(change) = rx.recv().await {
76//!         println!("Change detected: {:?} ({})", change.path, change.source);
77//!     }
78//!     Ok(())
79//! }
80//! ```
81
82// Core modules
83pub mod context;
84pub mod crdt;
85pub mod server;
86pub mod storage;
87pub mod sync;
88
89// Legacy watcher module (for CLI compatibility)
90#[path = "watcher_legacy/mod.rs"]
91pub mod watcher_legacy;
92
93// Production orchestration modules (v1.0.0)
94pub mod orchestrator;
95pub mod watcher;
96
97// DX Tools support modules
98pub mod version;
99pub mod patterns;
100pub mod injection;
101pub mod error;
102
103// Re-export orchestration types (public API)
104pub use orchestrator::{
105    Conflict, DxTool, ExecutionContext, Orchestrator, OrchestratorConfig, ToolOutput,
106    TrafficAnalyzer, TrafficBranch,
107};
108
109pub use watcher::{ChangeKind, ChangeSource, DualWatcher, FileChange, FileWatcher, LspWatcher};
110
111// Re-export storage types
112pub use context::{ComponentStateManager, UpdateResult};
113pub use crdt::{Operation, OperationType, Position};
114pub use storage::{Database, OperationLog};
115
116// Re-export DX tools support types
117pub use version::{ToolInfo, ToolRegistry, ToolSource, Version, VersionReq};
118pub use patterns::{DxToolType, PatternDetector, PatternMatch};
119pub use injection::{CacheStats, ComponentMetadata, InjectionManager};
120pub use error::{categorize_error, EnhancedError, EnhancedResult, ErrorCategory, RetryPolicy, ToEnhanced, with_retry};
121
122// Legacy exports (deprecated in favor of new watcher module)
123#[deprecated(since = "1.0.0", note = "use `watcher::DualWatcher` instead")]
124pub use watcher::DualWatcher as ForgeWatcher;
125
126/// Library version
127pub const VERSION: &str = env!("CARGO_PKG_VERSION");