MarketAlly.AIPlugin.Extensions/MarketAlly.AIPlugin.Refacto...
David Friedel 5cccf3c374 Initial commit - MarketAlly.AIPlugin extension modules
Includes:
- MarketAlly.AIPlugin.Analysis
- MarketAlly.AIPlugin.ClaudeCode
- MarketAlly.AIPlugin.Context
- MarketAlly.AIPlugin.DevOps
- MarketAlly.AIPlugin.Learning
- MarketAlly.AIPlugin.Refactoring
- MarketAlly.AIPlugin.Security
- MarketAlly.AIPlugin.All
- MarketAlly.ProjectDetector
- Test projects

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-27 22:14:33 +00:00
..
AI_LOG Initial commit - MarketAlly.AIPlugin extension modules 2025-12-27 22:14:33 +00:00
Caching Initial commit - MarketAlly.AIPlugin extension modules 2025-12-27 22:14:33 +00:00
Configuration Initial commit - MarketAlly.AIPlugin extension modules 2025-12-27 22:14:33 +00:00
Core Initial commit - MarketAlly.AIPlugin extension modules 2025-12-27 22:14:33 +00:00
Performance Initial commit - MarketAlly.AIPlugin extension modules 2025-12-27 22:14:33 +00:00
Pipeline Initial commit - MarketAlly.AIPlugin extension modules 2025-12-27 22:14:33 +00:00
Plugins Initial commit - MarketAlly.AIPlugin extension modules 2025-12-27 22:14:33 +00:00
Security Initial commit - MarketAlly.AIPlugin extension modules 2025-12-27 22:14:33 +00:00
Telemetry Initial commit - MarketAlly.AIPlugin extension modules 2025-12-27 22:14:33 +00:00
Tests Initial commit - MarketAlly.AIPlugin extension modules 2025-12-27 22:14:33 +00:00
AIReadmeEnhancementService.cs Initial commit - MarketAlly.AIPlugin extension modules 2025-12-27 22:14:33 +00:00
AIReadmeGeneratorPlugin.cs Initial commit - MarketAlly.AIPlugin extension modules 2025-12-27 22:14:33 +00:00
API_REFERENCE.md Initial commit - MarketAlly.AIPlugin extension modules 2025-12-27 22:14:33 +00:00
BatchRefactorPlugin.cs Initial commit - MarketAlly.AIPlugin extension modules 2025-12-27 22:14:33 +00:00
CodeAnalysisPlugin.cs Initial commit - MarketAlly.AIPlugin extension modules 2025-12-27 22:14:33 +00:00
CodeFormatterPlugin.cs Initial commit - MarketAlly.AIPlugin extension modules 2025-12-27 22:14:33 +00:00
CodeRefactoringPlugin.cs Initial commit - MarketAlly.AIPlugin extension modules 2025-12-27 22:14:33 +00:00
DocumentationServices.cs Initial commit - MarketAlly.AIPlugin extension modules 2025-12-27 22:14:33 +00:00
EnhancedDocumentationGeneratorPlugin.cs Initial commit - MarketAlly.AIPlugin extension modules 2025-12-27 22:14:33 +00:00
ErrorHandling.cs Initial commit - MarketAlly.AIPlugin extension modules 2025-12-27 22:14:33 +00:00
FileCache.cs Initial commit - MarketAlly.AIPlugin extension modules 2025-12-27 22:14:33 +00:00
GitHubCloneManager.cs Initial commit - MarketAlly.AIPlugin extension modules 2025-12-27 22:14:33 +00:00
GitRefactoringManager.cs Initial commit - MarketAlly.AIPlugin extension modules 2025-12-27 22:14:33 +00:00
InputValidator.cs Initial commit - MarketAlly.AIPlugin extension modules 2025-12-27 22:14:33 +00:00
IntelligentDescriptionPlugin.cs Initial commit - MarketAlly.AIPlugin extension modules 2025-12-27 22:14:33 +00:00
MarketAlly.AIPlugin.Refactoring.csproj Initial commit - MarketAlly.AIPlugin extension modules 2025-12-27 22:14:33 +00:00
MauiAwareSolutionScanner.cs Initial commit - MarketAlly.AIPlugin extension modules 2025-12-27 22:14:33 +00:00
NamingConventionPlugin.cs Initial commit - MarketAlly.AIPlugin extension modules 2025-12-27 22:14:33 +00:00
README.md Initial commit - MarketAlly.AIPlugin extension modules 2025-12-27 22:14:33 +00:00
ReadmeGeneratorPlugin.cs Initial commit - MarketAlly.AIPlugin extension modules 2025-12-27 22:14:33 +00:00
SharedUtilities.cs Initial commit - MarketAlly.AIPlugin extension modules 2025-12-27 22:14:33 +00:00
SimpleGitManager.cs Initial commit - MarketAlly.AIPlugin extension modules 2025-12-27 22:14:33 +00:00
SolutionRefactoringPlugin.cs Initial commit - MarketAlly.AIPlugin extension modules 2025-12-27 22:14:33 +00:00
icon-refactor.png Initial commit - MarketAlly.AIPlugin extension modules 2025-12-27 22:14:33 +00:00
refactorconfig.schema.json Initial commit - MarketAlly.AIPlugin extension modules 2025-12-27 22:14:33 +00:00

README.md

MarketAlly.AIPlugin.Refactoring

An enterprise-grade .NET 8.0 library for intelligent code refactoring with AI-powered analysis, performance optimization, and comprehensive security features.

🚀 Overview

MarketAlly.AIPlugin.Refactoring is a comprehensive refactoring solution that combines AI-powered code analysis with enterprise-grade performance, security, and monitoring capabilities. The library provides a plugin-based architecture for extensible refactoring operations with built-in caching, telemetry, and error handling.

Key Features

🔧 Core Functionality

  • AI-Powered Refactoring: Intelligent code analysis and refactoring suggestions
  • Plugin Architecture: Extensible system with 8+ specialized refactoring plugins
  • Pipeline Processing: Stage-based refactoring workflows with configurable stages
  • Multi-Format Support: C# code analysis using Microsoft.CodeAnalysis (Roslyn)

Performance & Scalability

  • Memory-Efficient Processing: Streaming support for large files (>50MB)
  • Adaptive Concurrency: Dynamic thread pool management based on system resources
  • Multi-Tier Caching: Syntax tree and analysis result caching with 80-90% performance improvements
  • Memory Pressure Monitoring: Automatic optimization based on available system memory

🔒 Security & Reliability

  • Path Traversal Protection: Comprehensive file system security validation
  • Input Sanitization: XSS, SQL injection, and command injection prevention
  • Secure File Processing: Extension validation and dangerous directory detection
  • Error Recovery: Circuit breaker patterns and automatic recovery strategies

📊 Monitoring & Observability

  • OpenTelemetry Integration: Distributed tracing and metrics collection
  • Performance Monitoring: Real-time system resource tracking
  • Comprehensive Telemetry: Operation success rates, duration metrics, and error tracking
  • Statistical Reporting: Detailed analytics and performance insights

⚙️ Configuration & Management

  • Multi-Source Configuration: Project, user, and global configuration hierarchy
  • JSON Schema Validation: Strongly-typed configuration with validation
  • Runtime Reconfiguration: Dynamic configuration updates without restarts
  • Environment-Specific Settings: Development, staging, and production configurations

🛠️ Installation

Package Manager

Install-Package MarketAlly.AIPlugin.Refactoring

.NET CLI

dotnet add package MarketAlly.AIPlugin.Refactoring

PackageReference

<PackageReference Include="MarketAlly.AIPlugin.Refactoring" Version="1.0.0" />

🚦 Quick Start

Basic Plugin Usage

using MarketAlly.AIPlugin.Refactoring.Core;
using MarketAlly.AIPlugin.Refactoring.Plugins;

// Create and execute a refactoring plugin
var codeAnalysisPlugin = new CodeAnalysisPlugin();
var parameters = new Dictionary<string, object>
{
    ["filePath"] = "/path/to/your/code.cs",
    ["analysisDepth"] = "comprehensive",
    ["includeComplexity"] = true
};

var result = await codeAnalysisPlugin.ExecuteAsync(parameters);
if (result.Success)
{
    Console.WriteLine($"Analysis completed: {result.Message}");
    // Process analysis results
}

Git Repository Management

using MarketAlly.AIPlugin.Refactoring.Plugins;

// Clone a repository for analysis
var clonePlugin = new GitHubClonePlugin();
var cloneParameters = new Dictionary<string, object>
{
    ["repository_url"] = "https://github.com/owner/repo.git",
    ["target_path"] = "/local/path/for/repo",
    ["branch"] = "main",
    ["shallow_clone"] = true
};

var cloneResult = await clonePlugin.ExecuteAsync(cloneParameters);
if (cloneResult.Success)
{
    var cloneData = (GitCloneResult)cloneResult.Data;
    Console.WriteLine($"Repository cloned successfully to {cloneData.TargetPath}");
    Console.WriteLine($"Latest commit: {cloneData.CommitHash}");
}

// Get repository status
var statusPlugin = new GitHubStatusPlugin();
var statusParameters = new Dictionary<string, object>
{
    ["repository_path"] = "/local/path/for/repo",
    ["check_remote_updates"] = true
};

var statusResult = await statusPlugin.ExecuteAsync(statusParameters);
if (statusResult.Success)
{
    var statusData = (GitRepositoryStatus)statusResult.Data;
    Console.WriteLine($"Current branch: {statusData.CurrentBranch}");
    Console.WriteLine($"Has remote updates: {statusData.HasRemoteUpdates}");
}

Pipeline-Based Processing

using MarketAlly.AIPlugin.Refactoring.Pipeline;
using MarketAlly.AIPlugin.Refactoring.Telemetry;

// Build a comprehensive refactoring pipeline
var pipeline = new RefactoringPipelineBuilder()
    .AddValidation()
    .AddFileDiscovery()
    .AddOperationExecution()
    .WithTelemetry(TelemetryFactory.Default)
    .Build();

// Configure refactoring context
var context = new RefactoringContext
{
    ProjectPath = "/path/to/project",
    Operations = { "analyze", "format", "document" },
    Parameters = new Dictionary<string, object>
    {
        ["complexityThreshold"] = 10,
        ["enableCaching"] = true
    }
};

// Execute the pipeline
var pipelineResult = await pipeline.ExecuteAsync(context);
Console.WriteLine($"Pipeline completed in {pipelineResult.TotalDuration.TotalMilliseconds}ms");

Configuration Management

using MarketAlly.AIPlugin.Refactoring.Configuration;

// Load hierarchical configuration (project -> user -> global)
var configManager = ConfigurationManagerFactory.Default;
var config = await configManager.LoadConfigurationAsync<RefactoringConfiguration>("CodeAnalysis");

// Use strongly-typed configuration
Console.WriteLine($"Max concurrency: {config.Performance.MaxConcurrency}");
Console.WriteLine($"Analysis depth: {config.CodeAnalysis.AnalysisDepth}");
Console.WriteLine($"Cache expiration: {config.Performance.CacheExpirationMinutes} minutes");

Custom Plugin Development

using MarketAlly.AIPlugin.Refactoring.Core;

public class CustomRefactoringPlugin : BaseAIPlugin
{
    public override IReadOnlyDictionary<string, Type> SupportedParameters =>
        new Dictionary<string, Type>
        {
            ["targetPath"] = typeof(string),
            ["options"] = typeof(CustomOptions)
        };

    protected override async Task<AIPluginResult> ExecuteInternalAsync(
        IReadOnlyDictionary<string, object> parameters)
    {
        // Automatic security validation, caching, and telemetry
        var targetPath = GetParameter<string>(parameters, "targetPath");
        var options = GetParameter<CustomOptions>(parameters, "options", new CustomOptions());

        // Use built-in caching and security features
        var syntaxTree = await GetSyntaxTreeAsync(targetPath);
        var analysisResult = await GetOrAnalyzeAsync(targetPath, 
            () => PerformCustomAnalysis(syntaxTree, options));

        return CreateSuccessResult(analysisResult, "Custom refactoring completed successfully");
    }

    private async Task<CustomAnalysisResult> PerformCustomAnalysis(
        SyntaxTree syntaxTree, CustomOptions options)
    {
        // Your custom analysis logic here
        return new CustomAnalysisResult();
    }
}

📚 Configuration

Project Configuration (.refactorconfig/plugin.json)

{
  "codeAnalysis": {
    "complexityThreshold": 10,
    "maxMethodLength": 50,
    "analysisDepth": "detailed",
    "enabledRules": ["long-method", "god-class", "duplicate-code"]
  },
  "performance": {
    "maxConcurrency": 4,
    "enableMemoryOptimization": true,
    "cacheExpirationMinutes": 30
  },
  "security": {
    "enablePathValidation": true,
    "allowedExtensions": [".cs", ".vb"]
  }
}

Schema Validation

The library includes a comprehensive JSON schema (refactorconfig.schema.json) for configuration validation with IntelliSense support in editors.

🏗️ Architecture

Core Components

  • BaseAIPlugin: Base class providing common functionality for all plugins
  • RefactoringPipeline: Stage-based processing pipeline with error handling
  • Configuration System: Multi-source configuration management with validation
  • Caching Infrastructure: Two-tier caching (memory + disk) with automatic invalidation
  • Security Layer: Path validation, input sanitization, and secure file processing
  • Telemetry System: OpenTelemetry-compatible monitoring and metrics collection

Performance Features

  • Memory-Efficient Processing: Automatic streaming for large files
  • Adaptive Concurrency: Dynamic thread pool based on system resources
  • Intelligent Caching: Content-hash based caching with file system monitoring
  • Resource Monitoring: Real-time system performance tracking

Security Features

  • Path Traversal Protection: Prevents directory traversal attacks
  • Input Validation: Comprehensive sanitization for all input parameters
  • Safe File Operations: Extension and content validation
  • Secure Configuration: Validated configuration loading with schema enforcement

📊 Performance Benchmarks

Operation Before After Improvement
Large File Processing (1GB) 2.5GB memory 400MB memory 84% reduction
Repeated Analysis 15s per run 1.2s per run 92% faster
Multi-file Operations Sequential Adaptive parallel 40-60% faster
Configuration Loading File I/O each time Cached 95% faster

🔍 Available Plugins

Core Refactoring Plugins

  1. CodeAnalysisPlugin: Comprehensive code analysis with complexity metrics
  2. CodeFormatterPlugin: Code formatting with multiple style options
  3. DocumentationGeneratorPlugin: AI-powered documentation generation
  4. NamingConventionPlugin: Intelligent naming analysis and suggestions
  5. BatchRefactorPlugin: Bulk operations across multiple files
  6. CodeRefactoringPlugin: General-purpose refactoring operations
  7. ReadmeGeneratorPlugin: Project documentation generation
  8. AIReadmeGeneratorPlugin: AI-enhanced README generation

Git Repository Management Plugins

  1. GitHubClonePlugin: Clone and validate GitHub repositories for analysis
  2. GitHubValidatePlugin: Validate repository accessibility and metadata
  3. GitHubStatusPlugin: Get status of cloned repositories with commit info
  4. GitHubUpdatePlugin: Pull latest changes from remote repositories

Enterprise Features

  • Pipeline Processing: Configurable multi-stage workflows
  • Error Recovery: Automatic recovery strategies with circuit breakers
  • Monitoring Integration: Real-time performance and health monitoring
  • Configuration Management: Hierarchical configuration with hot-reloading

🧪 Testing

# Run all tests
dotnet test

# Run with coverage
dotnet test --collect:"XPlat Code Coverage"

# Performance benchmarks
dotnet run --project Benchmarks --configuration Release

📈 Monitoring

Telemetry Integration

// Enable telemetry
var telemetry = TelemetryFactory.Create(logger);
telemetry.StartActivity("RefactoringOperation");

// Automatic metrics collection
await telemetry.TrackOperationAsync("CodeAnalysis", async () =>
{
    return await plugin.ExecuteAsync(parameters);
});

// View statistics
var stats = telemetry.GetStatistics();
Console.WriteLine($"Success rate: {stats.SuccessRate:P2}");

Performance Monitoring

// System resource monitoring
var monitor = TelemetryFactory.CreatePerformanceMonitor();
monitor.StartMonitoring();

// Generate performance reports
var report = await monitor.GenerateReportAsync(TimeSpan.FromHours(1));
Console.WriteLine($"Peak memory: {report.PeakMetrics.MemoryUsageBytes / 1024 / 1024}MB");

🛡️ Security Considerations

  • All file paths are validated against traversal attacks
  • Input parameters are sanitized to prevent injection attacks
  • Configuration files are validated against JSON schema
  • Plugin execution is sandboxed with proper error boundaries
  • Comprehensive audit logging for security events

🤝 Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Implement your changes with tests
  4. Ensure all security and performance checks pass
  5. Update documentation as needed
  6. Submit a pull request

Development Setup

# Clone the repository
git clone https://github.com/your-org/MarketAlly.AIPlugin.git

# Navigate to refactoring project
cd MarketAlly.AIPlugin/MarketAlly.AIPlugin.Refactoring

# Restore dependencies
dotnet restore

# Build the project
dotnet build

# Run tests
dotnet test

📋 Requirements

  • .NET 8.0 or later
  • 4GB+ RAM recommended for large-scale operations
  • Windows, macOS, or Linux

Dependencies

  • Microsoft.CodeAnalysis.CSharp (>= 4.5.0): Roslyn compiler APIs
  • LibGit2Sharp (>= 0.27.0): Git integration
  • Microsoft.Extensions.Logging (>= 8.0.0): Structured logging
  • System.Text.Json (>= 8.0.0): JSON serialization
  • System.Diagnostics.DiagnosticSource (>= 8.0.0): Telemetry

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

🚀 Roadmap

  • Visual Studio extension integration
  • Support for additional languages (VB.NET, F#)
  • Cloud-based analysis services
  • Machine learning-powered suggestions
  • Integration with popular CI/CD platforms

📞 Support

🏆 Enterprise Features

This library provides enterprise-grade features suitable for production environments:

  • High Performance: Optimized for large codebases with memory-efficient processing
  • Security First: Comprehensive security measures and input validation
  • Observability: Complete monitoring and telemetry integration
  • Reliability: Error recovery, circuit breakers, and fault tolerance
  • Scalability: Adaptive concurrency and resource management
  • Maintainability: Clean architecture with extensive documentation

Built with ❤️ for the developer community