Crate dx_forge

Crate dx_forge 

Source
Expand description

§DX Forge - Production-Ready VCS and Orchestration Engine

Forge is the orchestration backbone for the DX tools ecosystem, providing:

  • Content-addressable storage with SHA-256 blob hashing
  • Git-compatible versioning with traffic branch safety system
  • Dual-watcher architecture (LSP + File System monitoring)
  • Tool orchestration with priority-based execution and dependency resolution
  • Component injection for zero-bloat dependency management
  • Semantic versioning with dependency resolution
  • Pattern detection for dx-tools (dxButton, dxiIcon, dxfRoboto, etc.)
  • R2 component caching and injection
  • Production error handling with retry logic

§Architecture Overview

Forge eliminates node_modules bloat by detecting code patterns via LSP, injecting only needed components directly into user files, and coordinating DX tool execution with traffic branch safety logic.

§Core Components

  • Orchestrator: Coordinates tool execution with lifecycle hooks, circular dependency detection
  • Dual-Watcher: Monitors LSP + file system changes with pattern detection
  • Traffic Branch System: Green (auto), Yellow (merge), Red (manual) for safe updates
  • Storage Layer: Content-addressable blobs with R2 cloud sync
  • Version Manager: Semantic versioning with compatibility checking
  • Pattern Detector: Identifies dx-tool patterns in source code
  • Injection Manager: Fetches and caches components from R2 storage

§Quick Start - Tool Development

use dx_forge::{DxTool, ExecutionContext, ToolOutput, Orchestrator};
use async_trait::async_trait;
use anyhow::Result;

struct MyDxTool;

#[async_trait]
impl DxTool for MyDxTool {
    fn name(&self) -> &str { "dx-mytool" }
    fn version(&self) -> &str { "1.0.0" }
    fn priority(&self) -> i32 { 50 }
     
    async fn execute(&self, ctx: &ExecutionContext) -> Result<ToolOutput> {
        // Your tool logic here
        Ok(ToolOutput::success("Done!"))
    }
}

#[tokio::main]
async fn main() -> Result<()> {
    let mut orchestrator = Orchestrator::new(".")?;
    orchestrator.register_tool(Box::new(MyDxTool));
    orchestrator.execute_all().await?;
    Ok(())
}

§Quick Start - Change Detection

use dx_forge::{DualWatcher, FileChange};
use tokio::sync::broadcast;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    let watcher = DualWatcher::new(".")?;
    let mut rx = watcher.subscribe();
     
    tokio::spawn(async move {
        watcher.start().await
    });
     
    while let Ok(change) = rx.recv().await {
        println!("Change detected: {:?} ({})", change.path, change.source);
    }
    Ok(())
}

Re-exports§

pub use core::Forge;
pub use core::ForgeConfig;
pub use core::LifecycleEvent;
pub use core::ToolId;
pub use core::ToolStatus;
pub use core::EditorInfo;
pub use core::EditorType;
pub use core::OutputStrategy;
pub use core::GeneratedFileInfo;
pub use orchestrator::Conflict;
pub use orchestrator::DxTool;
pub use orchestrator::ExecutionContext;
pub use orchestrator::Orchestrator;
pub use orchestrator::OrchestratorConfig;
pub use orchestrator::ToolOutput;
pub use orchestrator::TrafficAnalyzer;
pub use orchestrator::TrafficBranch;
pub use watcher::ChangeKind;
pub use watcher::ChangeSource;
pub use watcher::DualWatcher;
pub use watcher::FileChange;
pub use watcher::FileWatcher;
pub use watcher::LspWatcher;
pub use context::ComponentStateManager;
pub use context::UpdateResult;
pub use crdt::Operation;
pub use crdt::OperationType;
pub use crdt::Position;
pub use storage::Database;
pub use storage::OperationLog;
pub use version::ToolInfo;
pub use version::ToolRegistry;
pub use version::ToolSource;
pub use version::Version;
pub use version::VersionReq;
pub use version::Snapshot;
pub use version::SnapshotId;
pub use version::SnapshotManager;
pub use version::Branch;
pub use version::ToolState;
pub use version::FileSnapshot;
pub use version::SnapshotDiff;
pub use patterns::DxToolType;
pub use patterns::PatternDetector;
pub use patterns::PatternMatch;
pub use injection::CacheStats;
pub use injection::ComponentMetadata;
pub use injection::InjectionManager;
pub use error::categorize_error;
pub use error::EnhancedError;
pub use error::EnhancedResult;
pub use error::ErrorCategory;
pub use error::RetryPolicy;
pub use error::ToEnhanced;
pub use error::with_retry;
pub use watcher::DualWatcher as ForgeWatcher;

Modules§

auto_update
Auto-Update System with Green Traffic Support
cache
Multi-layer Caching System
context
core
Core Forge functionality
crdt
error
Production Error Handling and Retry Logic
injection
Component Injection System
orchestrator
Simple Orchestrator - Only controls WHEN to run tools
patterns
LSP Pattern Detection for DX Tools
profiler
Performance Profiler for Critical Paths
server
storage
sync
version
Version control and tool registry
watcher
Dual-Watcher Architecture - LSP + File System monitoring
watcher_legacy

Macros§

profile
Profile a code block

Constants§

VERSION
Library version