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// Core library - NEW unified API
90pub mod core;
91
92// Legacy watcher module (for CLI compatibility)
93#[path = "watcher_legacy/mod.rs"]
94pub mod watcher_legacy;
95
96// Production orchestration modules (v1.0.0)
97pub mod orchestrator;
98pub mod watcher;
99
100// DX Tools support modules
101pub mod version;
102pub mod patterns;
103pub mod injection;
104pub mod error;
105
106// Phase 5 modules
107pub mod auto_update;
108pub mod profiler;
109pub mod cache;
110
111// ========================================================================
112// Primary Public API - Forge Unified Interface
113// ========================================================================
114
115pub use core::{
116    Forge, ForgeConfig,
117    LifecycleEvent, ToolId, ToolStatus,
118    EditorInfo, EditorType, OutputStrategy,
119    GeneratedFileInfo,
120};
121
122// ========================================================================
123// Re-export orchestration types (public API)
124// ========================================================================
125
126pub use orchestrator::{
127    Conflict, DxTool, ExecutionContext, Orchestrator, OrchestratorConfig, ToolOutput,
128    TrafficAnalyzer, TrafficBranch,
129};
130
131pub use watcher::{ChangeKind, ChangeSource, DualWatcher, FileChange, FileWatcher, LspWatcher};
132
133// ========================================================================
134// Re-export storage types
135// ========================================================================
136
137pub use context::{ComponentStateManager, UpdateResult};
138pub use crdt::{Operation, OperationType, Position};
139pub use storage::{Database, OperationLog};
140
141// ========================================================================
142// Re-export DX tools support types
143// ========================================================================
144
145pub use version::{
146    ToolInfo, ToolRegistry, ToolSource, Version, VersionReq,
147    Snapshot, SnapshotId, SnapshotManager, Branch, ToolState, FileSnapshot, SnapshotDiff,
148};
149pub use patterns::{DxToolType, PatternDetector, PatternMatch};
150pub use injection::{CacheStats, ComponentMetadata, InjectionManager};
151pub use error::{categorize_error, EnhancedError, EnhancedResult, ErrorCategory, RetryPolicy, ToEnhanced, with_retry};
152
153// ========================================================================
154// Legacy exports (deprecated in favor of new Forge API)
155// ========================================================================
156
157#[deprecated(since = "1.0.0", note = "use `Forge` instead")]
158pub use watcher::DualWatcher as ForgeWatcher;
159
160/// Library version
161pub const VERSION: &str = env!("CARGO_PKG_VERSION");
162
163// Testing forge logging
164// test logging
165// test event
166// event2
167// test edit