MarketAlly.AIPlugin.Extensions/MarketAlly.AIPlugin.Learning
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
Configuration Initial commit - MarketAlly.AIPlugin extension modules 2025-12-27 22:14:33 +00:00
Exceptions Initial commit - MarketAlly.AIPlugin extension modules 2025-12-27 22:14:33 +00:00
Models 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
Services 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
ComprehensiveLearningRefactorPlugin.cs Initial commit - MarketAlly.AIPlugin extension modules 2025-12-27 22:14:33 +00:00
Exceptions.cs Initial commit - MarketAlly.AIPlugin extension modules 2025-12-27 22:14:33 +00:00
GitManager.cs Initial commit - MarketAlly.AIPlugin extension modules 2025-12-27 22:14:33 +00:00
MarketAlly.AIPlugin.Learning.csproj Initial commit - MarketAlly.AIPlugin extension modules 2025-12-27 22:14:33 +00:00
Models.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
RefactorIQIntegration.cs Initial commit - MarketAlly.AIPlugin extension modules 2025-12-27 22:14:33 +00:00
RefactorIQRepository.cs Initial commit - MarketAlly.AIPlugin extension modules 2025-12-27 22:14:33 +00:00
ReportsManager.cs Initial commit - MarketAlly.AIPlugin extension modules 2025-12-27 22:14:33 +00:00
SelfLearningRefactorPlugin.cs Initial commit - MarketAlly.AIPlugin extension modules 2025-12-27 22:14:33 +00:00
UnifiedContextPlugin.cs Initial commit - MarketAlly.AIPlugin extension modules 2025-12-27 22:14:33 +00:00
appsettings.example.json Initial commit - MarketAlly.AIPlugin extension modules 2025-12-27 22:14:33 +00:00
icon-learning.png Initial commit - MarketAlly.AIPlugin extension modules 2025-12-27 22:14:33 +00:00

README.md

MarketAlly.AIPlugin.Learning

.NET 8.0 License Build Status

🚀 Revolutionary AI-Powered Learning & Refactoring System

MarketAlly.AIPlugin.Learning is the world's first unified AI development assistant that combines real-time code intelligence with historical memory to create an intelligent, self-improving refactoring system. It learns from past decisions, avoids previous mistakes, and builds organizational knowledge over time.

Key Features

🧠 Unified Context Intelligence

  • Real-time Code Analysis: Live code understanding with dependency tracking
  • Historical Memory: Learns from past conversations and decisions
  • Context-Informed Refactoring: Uses historical patterns to guide decisions
  • Predictive Analysis: Identifies issues before they occur

🔒 Enterprise-Grade Security

  • Path Validation: Prevents directory traversal attacks
  • Input Sanitization: Removes unsafe characters and validates inputs
  • File Access Control: Restricts access to approved file types and locations
  • Configuration Validation: Comprehensive settings validation

📊 Advanced Analytics

  • Structured Logging: Correlation IDs track operations across services
  • Performance Metrics: Detailed timing and resource usage statistics
  • Failure Pattern Analysis: Learns from unsuccessful attempts
  • Success Pattern Recognition: Identifies and reuses successful approaches

🏗️ Service-Oriented Architecture

  • Dependency Injection: Fully testable and maintainable design
  • Custom Exception Hierarchy: Specific error types for different scenarios
  • Resource Management: Proper IDisposable patterns throughout
  • Thread-Safe Operations: Concurrent collections and safe multi-threading

🚀 Quick Start

Installation

  1. Clone the repository
git clone https://github.com/your-org/MarketAlly.AIPlugin.git
cd MarketAlly.AIPlugin/MarketAlly.AIPlugin.Learning
  1. Restore dependencies
dotnet restore
  1. Build the project
dotnet build

Basic Usage

Using the Comprehensive Learning Plugin

var plugin = new ComprehensiveLearningRefactorPlugin();

var parameters = new Dictionary<string, object>
{
    ["solutionPath"] = @"C:\YourProject\Solution.sln",
    ["learningMode"] = "conservative",
    ["enableSemanticSearch"] = true,
    ["openAIApiKey"] = "your-openai-api-key",
    ["maxIterations"] = 20,
    ["verboseReporting"] = true
};

var result = await plugin.ExecuteAsync(parameters);

Using the Unified Context Service

// Initialize services
var services = new ServiceCollection();
services.AddSingleton<IUnifiedContextService, UnifiedContextService>();
var provider = services.BuildServiceProvider();

var contextService = provider.GetService<IUnifiedContextService>();

// Get comprehensive context combining real-time + historical data
var context = await contextService.PrepareFullContextAsync(
    "refactor this class for better maintainability",
    filePath: "MyClass.cs",
    maxTokens: 8000
);

// The context includes:
// - Current code analysis
// - Historical insights from past sessions
// - Related decisions from similar refactoring attempts
// - Project-wide context information

📋 Configuration

Learning Modes

Mode Description Max Iterations Risk Level
Conservative Safe, minimal changes 10 Low
Moderate Balanced approach 20 Medium
Aggressive Comprehensive refactoring 50 High

Configuration Example

{
  "Learning": {
    "Git": {
      "BranchPrefix": "ai-refactoring",
      "CommitterName": "AI Learning System",
      "CommitterEmail": "ai@learning.system"
    },
    "LearningModes": {
      "Conservative": {
        "MaxIterations": 10,
        "MaxAttemptsPerFile": 2,
        "EnableRiskyRefactorings": false
      },
      "Moderate": {
        "MaxIterations": 20,
        "MaxAttemptsPerFile": 3,
        "EnableRiskyRefactorings": true
      },
      "Aggressive": {
        "MaxIterations": 50,
        "MaxAttemptsPerFile": 5,
        "EnableRiskyRefactorings": true
      }
    },
    "AI": {
      "EnableSemanticSearch": true,
      "MaxSearchResults": 10,
      "MinSimilarityScore": 0.7,
      "MaxContextTokens": 8000
    },
    "Security": {
      "ForbiddenDirectories": ["bin", "obj", ".git", "node_modules"],
      "AllowedFileExtensions": [".cs", ".csproj", ".sln"],
      "MaxFileSize": 10485760
    }
  }
}

🎯 Core Services

LearningOrchestrator

Main orchestration service that coordinates the entire learning session.

public interface ILearningOrchestrator : IDisposable
{
    Task<ComprehensiveLearningResult> ExecuteCompleteLearningSessionAsync(
        ComprehensiveLearningSession session);
}

UnifiedContextService

Revolutionary service combining real-time and historical intelligence.

public interface IUnifiedContextService
{
    Task<ComprehensiveContext> PrepareFullContextAsync(string query, string? filePath = null, int maxTokens = 8000);
    Task<LearningSessionContext> InitializeLearningSessionAsync(string projectPath, string topic);
    Task StoreLearningInsightAsync(string insight, string category, string? filePath = null);
    Task<List<HistoricalInsight>> FindSimilarPastIssuesAsync(string currentIssue);
    Task StoreRefactoringDecisionAsync(string decision, string reasoning, string filePath, bool successful);
}

SecurityService

Comprehensive security validation and sanitization.

public interface ISecurityService
{
    bool IsPathSafe(string path);
    bool IsFileAllowed(string filePath);
    string SanitizeInput(string input);
    ValidationResult ValidateConfiguration(LearningConfiguration config);
    string GenerateSecureSessionId();
}

LLMContextService

Intelligent LLM context preparation with dependency tracking.

public interface ILLMContextService
{
    Task<LLMContext> PrepareContextAsync(string query, int maxTokens = 4000);
    Task<LLMContext> PrepareCodeAnalysisContextAsync(string filePath, string query, int maxTokens = 4000);
    Task<DependencyContext> GetDependencyContextAsync(string symbolName);
    Task<ChangeImpactContext> AnalyzeChangeImpactAsync(string filePath, int lineNumber);
}

🔧 Advanced Usage

Learning Session with Historical Context

// Initialize learning session
var sessionContext = await unifiedContextService.InitializeLearningSessionAsync(
    projectPath: @"C:\MyProject",
    topic: "Performance optimization refactoring"
);

// Get context for specific refactoring decision
var context = await unifiedContextService.PrepareFullContextAsync(
    "optimize database queries in UserService",
    filePath: "Services/UserService.cs"
);

// Check for similar past issues
var similarIssues = await unifiedContextService.FindSimilarPastIssuesAsync(
    "database query performance UserService"
);

if (similarIssues.Any(i => i.Tags.Contains("successful")))
{
    Console.WriteLine("Found successful patterns from previous attempts!");
}

// Store refactoring decision for future learning
await unifiedContextService.StoreRefactoringDecisionAsync(
    decision: "Applied query caching pattern",
    reasoning: "Reduced database calls by 80% with minimal complexity",
    filePath: "Services/UserService.cs",
    successful: true
);

Custom Learning Mode

var customSession = new ComprehensiveLearningSession
{
    SessionId = Guid.NewGuid(),
    SolutionPath = @"C:\MyProject\Solution.sln",
    LearningMode = "aggressive",
    MaxIterations = 30,
    EnableSemanticSearch = true,
    OpenAIApiKey = Environment.GetEnvironmentVariable("OPENAI_API_KEY"),
    SessionTimeoutMinutes = 120,
    VerboseReporting = true
};

using var orchestrator = serviceProvider.GetRequiredService<ILearningOrchestrator>();
var result = await orchestrator.ExecuteCompleteLearningSessionAsync(customSession);

📊 Monitoring and Observability

Structured Logging

All operations include correlation IDs for tracing:

_logger.LogInformation(
    "🚀 Starting learning session for: {ProjectName} [CorrelationId: {CorrelationId}]", 
    projectName, correlationId);

Performance Metrics

Track operation performance:

var result = await orchestrator.ExecuteCompleteLearningSessionAsync(session);

Console.WriteLine($"Session Duration: {result.TotalDuration.TotalMinutes:F1} minutes");
Console.WriteLine($"Successful Iterations: {result.Iterations.Count(i => i.Success)}");
Console.WriteLine($"Failed Attempts: {result.FailedAttempts.Count}");
Console.WriteLine($"AI Features Enabled: {result.AIFeaturesEnabled}");

🧪 Testing

Unit Tests

[Test]
public async Task UnifiedContextService_Should_CombineRealTimeAndHistorical()
{
    // Arrange
    var mockLLMService = new Mock<ILLMContextService>();
    var service = new UnifiedContextService(mockLLMService.Object, options, logger);
    
    // Act
    var context = await service.PrepareFullContextAsync("test query");
    
    // Assert
    Assert.That(context.CurrentCodeAnalysis, Is.Not.Null);
    Assert.That(context.HistoricalInsights, Is.Not.Empty);
}

Integration Tests

[Test]
public async Task LearningOrchestrator_Should_ExecuteCompleteSession()
{
    // Arrange
    var session = CreateTestSession();
    
    // Act
    var result = await orchestrator.ExecuteCompleteLearningSessionAsync(session);
    
    // Assert
    Assert.That(result.Success, Is.True);
    Assert.That(result.Iterations, Is.Not.Empty);
}

🛡️ Security Considerations

Path Validation

// Automatically validates all file paths
if (!securityService.IsPathSafe(filePath))
{
    throw new SecurityException("Path validation failed");
}

Input Sanitization

// All user inputs are sanitized
var sanitizedQuery = securityService.SanitizeInput(userQuery);

File Access Control

// Only approved file types are processed
var allowedExtensions = new[] { ".cs", ".csproj", ".sln" };

🚀 Performance Optimizations

Context Caching

  • LLM context results are cached to avoid redundant computation
  • Cache keys based on query, file path, and token limits
  • Thread-safe concurrent dictionary implementation

Resource Management

  • Proper IDisposable patterns throughout
  • Using statements for automatic cleanup
  • Service provider disposal handling

Thread Safety

  • ConcurrentDictionary for file attempt tracking
  • Thread-safe collections for multi-threaded scenarios
  • Correlation ID tracking across async operations

📈 Metrics and Analytics

Session Metrics

  • Total duration and iteration count
  • Success/failure ratios
  • AI feature utilization
  • Resource consumption patterns

Learning Analytics

  • Historical pattern recognition
  • Decision success rates
  • Failure pattern analysis
  • Organizational knowledge growth

🔮 Roadmap

Upcoming Features

  • Health Checks: Service monitoring and diagnostics
  • Retry Policies: Resilient operation handling
  • Event Sourcing: Complete audit trail capability
  • ML Model Integration: Custom learning models
  • Real-time Collaboration: Multi-developer session support

Integration Enhancements

  • IDE Extensions: Visual Studio and VS Code plugins
  • CI/CD Integration: GitHub Actions and Azure DevOps
  • Cloud Services: Azure/AWS deployment options
  • Enterprise SSO: Active Directory integration

🤝 Contributing

We welcome contributions! Please see our Contributing Guidelines for details.

Development Setup

  1. Prerequisites

    • .NET 8.0 SDK
    • Git
    • Visual Studio 2022 or VS Code
  2. Development Environment

git clone https://github.com/your-org/MarketAlly.AIPlugin.git
cd MarketAlly.AIPlugin/MarketAlly.AIPlugin.Learning
dotnet restore
dotnet build
dotnet test
  1. Code Standards
    • Follow C# coding conventions
    • Include comprehensive XML documentation
    • Add unit tests for new features
    • Update documentation for API changes

📄 License

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

🙏 Acknowledgments

  • RefactorIQ: Advanced code analysis capabilities
  • LibGit2Sharp: Git operations integration
  • Microsoft.CodeAnalysis: Roslyn compiler platform
  • OpenAI: AI embeddings and semantic search

📞 Support


Built with ❤️ by the MarketAlly Team

Revolutionizing AI-assisted development through intelligent learning and historical memory.