# API Reference - MarketAlly.AIPlugin.Learning
## Table of Contents
- [Core Interfaces](#core-interfaces)
- [Service Implementations](#service-implementations)
- [Data Models](#data-models)
- [Configuration Classes](#configuration-classes)
- [Exception Types](#exception-types)
- [Plugin Interfaces](#plugin-interfaces)
- [Usage Examples](#usage-examples)
---
## Core Interfaces
### ILearningOrchestrator
Main orchestration service interface for coordinating learning sessions.
```csharp
public interface ILearningOrchestrator : IDisposable
{
///
/// Executes a complete learning session with all phases
///
/// Learning session configuration
/// Comprehensive results with metrics and analysis
Task ExecuteCompleteLearningSessionAsync(
ComprehensiveLearningSession session);
}
```
**Implementation**: `LearningOrchestrator`
**Lifecycle**: Transient (create per session)
**Thread Safety**: Single-threaded per instance
---
### IUnifiedContextService
Revolutionary service combining real-time code intelligence with historical memory.
```csharp
public interface IUnifiedContextService
{
///
/// Prepares comprehensive context combining current code analysis with historical insights
///
/// Query describing the operation or question
/// Optional specific file to analyze
/// Maximum tokens for the complete context
/// Comprehensive context with real-time and historical data
Task PrepareFullContextAsync(
string query,
string? filePath = null,
int maxTokens = 8000);
///
/// Initializes a new learning session with project context
///
/// Path to the project being analyzed
/// Topic or focus area for the session
/// Session context with project information
Task InitializeLearningSessionAsync(
string projectPath,
string topic);
///
/// Stores a learning insight for future reference
///
/// The insight or lesson learned
/// Category for organization (e.g., "refactoring", "performance")
/// Optional file path associated with the insight
/// Optional metadata for the insight
Task StoreLearningInsightAsync(
string insight,
string category,
string? filePath = null,
Dictionary? metadata = null);
///
/// Finds similar past issues or patterns for guidance
///
/// Description of the current issue or task
/// Optional project path for context
/// List of relevant historical insights
Task> FindSimilarPastIssuesAsync(
string currentIssue,
string? projectPath = null);
///
/// Retrieves decisions related to a symbol or operation type
///
/// Name of the symbol (class, method, etc.)
/// Optional operation type filter
/// List of related previous decisions
Task> GetRelatedDecisionsAsync(
string symbolName,
string? operationType = null);
///
/// Stores a refactoring decision with outcome for future learning
///
/// The decision that was made
/// Reasoning behind the decision
/// File path where the decision was applied
/// Whether the decision was successful
Task StoreRefactoringDecisionAsync(
string decision,
string reasoning,
string filePath,
bool successful);
///
/// Finalizes a learning session and stores summary metrics
///
/// Summary of the session
/// Session metrics and statistics
/// Session summary with finalization details
Task FinalizeLearningSessionAsync(
string sessionSummary,
Dictionary metrics);
}
```
**Implementation**: `UnifiedContextService`
**Lifecycle**: Singleton (shared across sessions)
**Thread Safety**: Thread-safe with concurrent collections
---
### ILLMContextService
Intelligent LLM context preparation service with advanced code analysis.
```csharp
public interface ILLMContextService
{
///
/// Prepares optimized context for LLM consumption
///
/// The query or task description
/// Maximum tokens for the context
/// Optimized LLM context
Task PrepareContextAsync(string query, int maxTokens = 4000);
///
/// Prepares context focused on specific code file analysis
///
/// Path to the file to analyze
/// Specific query about the file
/// Maximum tokens for the context
/// File-focused LLM context
Task PrepareCodeAnalysisContextAsync(
string filePath,
string query,
int maxTokens = 4000);
///
/// Gets dependency context for a specific symbol
///
/// Name of the symbol to analyze
/// Dependency context with related symbols
Task GetDependencyContextAsync(string symbolName);
///
/// Analyzes potential impact of changes at specific location
///
/// File path where change will be made
/// Line number of the change
/// Change impact analysis
Task AnalyzeChangeImpactAsync(string filePath, int lineNumber);
///
/// Gets code relationships for a symbol (callers, callees, dependencies)
///
/// Symbol to analyze relationships for
/// Code relationship context
Task GetCodeRelationshipsAsync(string symbolName);
}
```
**Implementation**: `LLMContextService`
**Lifecycle**: Singleton (caching benefits)
**Thread Safety**: Thread-safe with cache synchronization
---
### ISecurityService
Comprehensive security validation and sanitization service.
```csharp
public interface ISecurityService
{
///
/// Validates that a path is safe and within allowed boundaries
///
/// Path to validate
/// True if path is safe, false otherwise
bool IsPathSafe(string path);
///
/// Checks if a file is allowed based on security policies
///
/// File path to check
/// True if file access is allowed
bool IsFileAllowed(string filePath);
///
/// Sanitizes user input by removing unsafe characters
///
/// Input string to sanitize
/// Sanitized input string
string SanitizeInput(string input);
///
/// Validates learning configuration for security compliance
///
/// Configuration to validate
/// Validation result with any errors
ValidationResult ValidateConfiguration(LearningConfiguration config);
///
/// Generates a cryptographically secure session identifier
///
/// Secure session ID
string GenerateSecureSessionId();
///
/// Validates that a directory is within working directory bounds
///
/// Directory path to validate
/// True if directory is within bounds
bool IsDirectoryWithinBounds(string directory);
///
/// Checks if an operation is allowed based on current session context
///
/// Operation to validate
/// Current session context
/// True if operation is allowed
bool IsOperationAllowed(string operation, SessionContext context);
}
```
**Implementation**: `SecurityService`
**Lifecycle**: Singleton (stateless validation)
**Thread Safety**: Thread-safe (immutable state)
---
## Service Implementations
### LearningOrchestrator
```csharp
public class LearningOrchestrator : ILearningOrchestrator, IDisposable
{
// Constructor with dependency injection
public LearningOrchestrator(
ILogger logger,
IOptions configOptions,
ISecurityService securityService,
ILLMContextService llmContextService,
IUnifiedContextService unifiedContextService,
GitManager gitManager,
CompilationManager compilationManager,
ReportsManager reportsManager,
RefactorIQIntegration refactorIQIntegration);
// Main execution method
public async Task ExecuteCompleteLearningSessionAsync(
ComprehensiveLearningSession session);
// Proper disposal pattern
public void Dispose();
protected virtual void Dispose(bool disposing);
}
```
**Key Features:**
- **Phase-based execution**: Git setup → Analysis → Iterations → Reporting
- **Correlation ID tracking**: Traces operations across service calls
- **Resource management**: Proper disposal of all resources
- **Security integration**: Validates all inputs and file access
- **Error recovery**: Handles failures gracefully with detailed reporting
### UnifiedContextService
```csharp
public class UnifiedContextService : IUnifiedContextService
{
// Constructor
public UnifiedContextService(
ILLMContextService llmContextService,
IOptions options,
ILogger logger);
// Core context preparation method
public async Task PrepareFullContextAsync(
string query,
string? filePath = null,
int maxTokens = 8000);
}
```
**Key Features:**
- **Context combination**: Merges real-time and historical data
- **Token optimization**: Respects LLM token limits intelligently
- **Caching**: Performance optimization with concurrent cache
- **Mock integration**: Ready for Context project when available
---
## Data Models
### ComprehensiveContext
```csharp
public class ComprehensiveContext
{
/// Original query that generated this context
public string Query { get; set; } = string.Empty;
/// File path if context is file-specific
public string? FilePath { get; set; }
/// Maximum tokens requested for this context
public int MaxTokens { get; set; }
/// When this context was generated
public DateTime GeneratedAt { get; set; }
/// Correlation ID for tracing
public string CorrelationId { get; set; } = string.Empty;
/// Current/real-time code analysis
public LLMContext? CurrentCodeAnalysis { get; set; }
/// Historical insights from past sessions
public List HistoricalInsights { get; set; } = new();
/// Previous decisions about similar code
public List RelatedDecisions { get; set; } = new();
/// Project-wide context information
public ProjectContextInfo? ProjectContext { get; set; }
/// Estimated total tokens in this context
public int EstimatedTotalTokens { get; set; }
}
```
### LLMContext
```csharp
public class LLMContext
{
/// Code chunks relevant to the query
public List CodeChunks { get; set; } = new();
/// Dependencies and related symbols
public List Dependencies { get; set; } = new();
/// Estimated token count for this context
public int EstimatedTokens { get; set; }
/// Context generation metadata
public Dictionary Metadata { get; set; } = new();
/// Files that might be affected by changes
public List AffectedFiles { get; set; } = new();
/// Code relationships and dependencies
public CodeRelationshipMap RelationshipMap { get; set; } = new();
}
```
### HistoricalInsight
```csharp
public class HistoricalInsight
{
/// Unique identifier for the insight
public string Id { get; set; } = string.Empty;
/// Full content of the insight
public string Content { get; set; } = string.Empty;
/// Brief summary of the insight
public string Summary { get; set; } = string.Empty;
/// Relevance score (0.0 to 1.0)
public double Relevance { get; set; }
/// When this insight was recorded
public DateTime Timestamp { get; set; }
/// Tags for categorization and search
public List Tags { get; set; } = new();
}
```
### PreviousDecision
```csharp
public class PreviousDecision
{
/// Unique identifier for the decision
public string Id { get; set; } = string.Empty;
/// Full content of the decision
public string Content { get; set; } = string.Empty;
/// Brief summary of the decision
public string Summary { get; set; } = string.Empty;
/// Relevance score (0.0 to 1.0)
public double Relevance { get; set; }
/// When this decision was made
public DateTime Timestamp { get; set; }
/// Whether the decision was successful
public bool Successful { get; set; }
/// Tags for categorization and search
public List Tags { get; set; } = new();
}
```
### ComprehensiveLearningSession
```csharp
public class ComprehensiveLearningSession
{
/// Unique session identifier
public Guid SessionId { get; set; }
/// Path to the solution file
public string SolutionPath { get; set; } = string.Empty;
/// Directory for generated reports
public string ReportsDirectory { get; set; } = "Reports";
/// Learning mode: conservative, moderate, aggressive
public string LearningMode { get; set; } = "conservative";
/// Maximum iterations for this session
public int MaxIterations { get; set; } = 20;
/// Maximum attempts per file before giving up
public int MaxAttemptsPerFile { get; set; } = 3;
/// Session timeout in minutes
public int SessionTimeoutMinutes { get; set; } = 60;
/// Enable verbose reporting
public bool VerboseReporting { get; set; } = false;
/// Skip warnings analysis phase
public bool SkipWarningsAnalysis { get; set; } = false;
/// Enable AI embeddings and semantic search
public bool EnableSemanticSearch { get; set; } = false;
/// OpenAI API key for embeddings (optional)
public string? OpenAIApiKey { get; set; }
/// Session start time
public DateTime StartTime { get; set; }
}
```
### ComprehensiveLearningResult
```csharp
public class ComprehensiveLearningResult
{
/// Session identifier
public Guid SessionId { get; set; }
/// Session start time
public DateTime StartTime { get; set; }
/// Session end time
public DateTime EndTime { get; set; }
/// Total session duration
public TimeSpan TotalDuration { get; set; }
/// Project name being analyzed
public string ProjectName { get; set; } = string.Empty;
/// Whether the session completed successfully
public bool Success { get; set; }
/// Whether a critical error occurred
public bool CriticalError { get; set; }
/// Error message if session failed
public string? ErrorMessage { get; set; }
/// All learning iterations performed
public List Iterations { get; set; } = new();
/// Failed attempts across all iterations
public List FailedAttempts { get; set; } = new();
/// Git branch information
public GitBranchInfo GitInfo { get; set; } = new();
/// Baseline compilation results
public CompilationResult? BaselineCompilation { get; set; }
/// Final compilation results
public CompilationResult? FinalCompilation { get; set; }
/// Initial RefactorIQ analysis results
public RefactorIQAnalysisResult? InitialRefactorIQAnalysis { get; set; }
/// Whether AI features were enabled and used
public bool AIFeaturesEnabled { get; set; }
/// Semantic search results from AI analysis
public List? SemanticSearchResults { get; set; }
}
```
---
## Configuration Classes
### LearningConfiguration
```csharp
[ConfigurationSection("Learning")]
public class LearningConfiguration
{
public const string SectionName = "Learning";
/// Git-related configuration
[Required]
public GitConfiguration Git { get; set; } = new();
/// Security and validation settings
[Required]
public SecurityConfiguration Security { get; set; } = new();
/// Performance tuning parameters
[Required]
public PerformanceConfiguration Performance { get; set; } = new();
/// AI service configuration
[Required]
public AIConfiguration AI { get; set; } = new();
/// Learning mode configurations
[Required]
public LearningModeConfiguration LearningModes { get; set; } = new();
}
```
### GitConfiguration
```csharp
public class GitConfiguration
{
/// Prefix for AI-generated branches
[Required]
public string BranchPrefix { get; set; } = "ai-refactoring";
/// Name for git commits
[Required]
public string CommitterName { get; set; } = "AI Learning System";
/// Email for git commits
[Required]
[EmailAddress]
public string CommitterEmail { get; set; } = "ai@learning.system";
/// Whether to create safety branches
public bool CreateSafetyBranches { get; set; } = true;
/// Whether to automatically merge successful iterations
public bool AutoMergeSuccessful { get; set; } = true;
/// Maximum depth for git operations
[Range(1, 100)]
public int MaxDepth { get; set; } = 10;
}
```
### SecurityConfiguration
```csharp
public class SecurityConfiguration
{
/// Directories that are forbidden from access
[Required]
public List ForbiddenDirectories { get; set; } = new()
{
"bin", "obj", ".git", "node_modules", ".vs", "packages"
};
/// File extensions that are allowed for processing
[Required]
public List AllowedFileExtensions { get; set; } = new()
{
".cs", ".csproj", ".sln", ".json", ".xml"
};
/// Maximum file size in bytes
[Range(1024, int.MaxValue)]
public long MaxFileSize { get; set; } = 10 * 1024 * 1024; // 10MB
/// Maximum path length
[Range(10, 32767)]
public int MaxPathLength { get; set; } = 260;
/// Whether to validate file contents for malicious patterns
public bool ValidateFileContents { get; set; } = true;
/// Patterns that are considered unsafe in file paths
public List UnsafePathPatterns { get; set; } = new()
{
"..", "~", "%", "$"
};
}
```
### AIConfiguration
```csharp
public class AIConfiguration
{
/// Whether to enable semantic search features
public bool EnableSemanticSearch { get; set; } = false;
/// Maximum number of search results to return
[Range(1, 100)]
public int MaxSearchResults { get; set; } = 10;
/// Minimum similarity score for search results
[Range(0.0, 1.0)]
public double MinSimilarityScore { get; set; } = 0.7;
/// Maximum tokens for LLM context
[Range(100, 32000)]
public int MaxContextTokens { get; set; } = 8000;
/// Whether to enable context caching
public bool EnableContextCaching { get; set; } = true;
/// Cache expiration time in minutes
[Range(1, 1440)]
public int CacheExpirationMinutes { get; set; } = 60;
/// OpenAI API configuration
public OpenAIConfiguration OpenAI { get; set; } = new();
}
```
### LearningModeConfiguration
```csharp
public class LearningModeConfiguration
{
/// Conservative learning mode settings
[Required]
public LearningModeSettings Conservative { get; set; } = new()
{
MaxIterations = 10,
MaxAttemptsPerFile = 2,
EnableRiskyRefactorings = false,
RequireCompilationSuccess = true
};
/// Moderate learning mode settings
[Required]
public LearningModeSettings Moderate { get; set; } = new()
{
MaxIterations = 20,
MaxAttemptsPerFile = 3,
EnableRiskyRefactorings = true,
RequireCompilationSuccess = true
};
/// Aggressive learning mode settings
[Required]
public LearningModeSettings Aggressive { get; set; } = new()
{
MaxIterations = 50,
MaxAttemptsPerFile = 5,
EnableRiskyRefactorings = true,
RequireCompilationSuccess = false
};
}
public class LearningModeSettings
{
/// Maximum iterations for this mode
[Range(1, 100)]
public int MaxIterations { get; set; }
/// Maximum attempts per file
[Range(1, 10)]
public int MaxAttemptsPerFile { get; set; }
/// Whether to enable risky refactorings
public bool EnableRiskyRefactorings { get; set; }
/// Whether compilation must succeed to continue
public bool RequireCompilationSuccess { get; set; }
/// Timeout per iteration in minutes
[Range(1, 60)]
public int IterationTimeoutMinutes { get; set; } = 5;
}
```
---
## Exception Types
### Base Exception
```csharp
///
/// Base exception for all learning-related errors
///
public abstract class LearningException : Exception
{
/// Operation context where the error occurred
public string OperationContext { get; }
/// Correlation ID for tracing
public string CorrelationId { get; }
protected LearningException(string operationContext, string message)
: base(message)
{
OperationContext = operationContext;
CorrelationId = Guid.NewGuid().ToString("N")[..8];
}
protected LearningException(string operationContext, string message, Exception innerException)
: base(message, innerException)
{
OperationContext = operationContext;
CorrelationId = Guid.NewGuid().ToString("N")[..8];
}
}
```
### Specific Exception Types
```csharp
/// Compilation-related errors with detailed metrics
public class CompilationException : LearningException
{
public int ErrorCount { get; }
public int WarningCount { get; }
public IReadOnlyList Errors { get; }
public CompilationException(int errorCount, int warningCount, IEnumerable errors)
: base("Compilation", $"Compilation failed with {errorCount} errors and {warningCount} warnings")
{
ErrorCount = errorCount;
WarningCount = warningCount;
Errors = errors.ToList().AsReadOnly();
}
}
/// RefactorIQ operation failures
public class RefactorIQException : LearningException
{
public string? ConfigPath { get; }
public RefactorIQException(string operation, string? configPath, string message, Exception? innerException = null)
: base($"RefactorIQ.{operation}", message, innerException ?? new InvalidOperationException())
{
ConfigPath = configPath;
}
}
/// Security validation failures
public class SecurityException : LearningException
{
public string ValidationType { get; }
public string? ViolatingValue { get; }
public SecurityException(string validationType, string? violatingValue, string message)
: base($"Security.{validationType}", message)
{
ValidationType = validationType;
ViolatingValue = violatingValue;
}
}
/// Configuration validation errors
public class ConfigurationException : LearningException
{
public string ConfigurationKey { get; }
public ConfigurationException(string configurationKey, string message)
: base("Configuration", message)
{
ConfigurationKey = configurationKey;
}
}
/// Git operation failures
public class GitOperationException : LearningException
{
public string GitOperation { get; }
public string? RepositoryPath { get; }
public GitOperationException(string gitOperation, string? repositoryPath, string message)
: base($"Git.{gitOperation}", message)
{
GitOperation = gitOperation;
RepositoryPath = repositoryPath;
}
}
/// AI service operation failures
public class AIServiceException : LearningException
{
public string ServiceName { get; }
public bool IsRetryable { get; }
public AIServiceException(string serviceName, string message, Exception? innerException = null, bool isRetryable = false)
: base($"AIService.{serviceName}", message, innerException ?? new InvalidOperationException())
{
ServiceName = serviceName;
IsRetryable = isRetryable;
}
}
```
---
## Plugin Interfaces
### ComprehensiveLearningRefactorPlugin
```csharp
[AIPlugin("ComprehensiveLearningRefactor",
"Complete self-learning refactoring system with unified context intelligence")]
public class ComprehensiveLearningRefactorPlugin : IAIPlugin, IDisposable
{
// Plugin parameters
[AIParameter("Solution path to analyze and improve", required: true)]
public string SolutionPath { get; set; }
[AIParameter("Learning mode: conservative, moderate, aggressive", required: false)]
public string LearningMode { get; set; } = "conservative";
[AIParameter("Enable semantic code search", required: false)]
public bool EnableSemanticSearch { get; set; } = false;
[AIParameter("OpenAI API key for embeddings", required: false)]
public string OpenAIApiKey { get; set; }
// Main execution method
public async Task ExecuteAsync(IReadOnlyDictionary parameters);
// Supported parameters definition
public IReadOnlyDictionary SupportedParameters { get; }
// Resource cleanup
public void Dispose();
}
```
### UnifiedContextPlugin
```csharp
[AIPlugin("UnifiedContext",
"Unified context service combining real-time code analysis with historical memory")]
public class UnifiedContextPlugin : IAIPlugin, IDisposable
{
// Supported actions
public static class Actions
{
public const string PrepareContext = "prepare-context";
public const string InitializeSession = "initialize-session";
public const string StoreInsight = "store-insight";
public const string FindSimilar = "find-similar";
public const string GetDecisions = "get-decisions";
public const string StoreDecision = "store-decision";
public const string FinalizeSession = "finalize-session";
}
// Action-specific parameter validation
private readonly Dictionary> _requiredParametersByAction = new()
{
[Actions.PrepareContext] = new() { "query" },
[Actions.InitializeSession] = new() { "projectPath", "topic" },
[Actions.StoreInsight] = new() { "insight", "category" },
[Actions.FindSimilar] = new() { "currentIssue" },
[Actions.GetDecisions] = new() { "symbolName" },
[Actions.StoreDecision] = new() { "decision", "reasoning", "filePath", "successful" },
[Actions.FinalizeSession] = new() { "sessionSummary", "metrics" }
};
}
```
---
## Usage Examples
### Basic Learning Session
```csharp
// Setup dependency injection
var services = new ServiceCollection();
services.AddSingleton();
services.AddSingleton();
services.AddSingleton();
services.AddTransient();
var serviceProvider = services.BuildServiceProvider();
// Create and execute learning session
var session = new ComprehensiveLearningSession
{
SessionId = Guid.NewGuid(),
SolutionPath = @"C:\MyProject\Solution.sln",
LearningMode = "moderate",
EnableSemanticSearch = true,
MaxIterations = 25,
SessionTimeoutMinutes = 90
};
using var orchestrator = serviceProvider.GetRequiredService();
var result = await orchestrator.ExecuteCompleteLearningSessionAsync(session);
// Process results
Console.WriteLine($"Session completed: {result.Success}");
Console.WriteLine($"Duration: {result.TotalDuration.TotalMinutes:F1} minutes");
Console.WriteLine($"Iterations: {result.Iterations.Count}");
Console.WriteLine($"Successful: {result.Iterations.Count(i => i.Success)}");
```
### Advanced Context Preparation
```csharp
var contextService = serviceProvider.GetRequiredService();
// Initialize learning session
var sessionContext = await contextService.InitializeLearningSessionAsync(
projectPath: @"C:\MyProject",
topic: "Performance optimization and code cleanup"
);
// Prepare comprehensive context for specific task
var context = await contextService.PrepareFullContextAsync(
query: "optimize database access patterns in UserService",
filePath: @"C:\MyProject\Services\UserService.cs",
maxTokens: 12000
);
// Analyze the context
Console.WriteLine($"Current code analysis tokens: {context.CurrentCodeAnalysis?.EstimatedTokens}");
Console.WriteLine($"Historical insights: {context.HistoricalInsights.Count}");
Console.WriteLine($"Related decisions: {context.RelatedDecisions.Count}");
// Check for successful patterns from history
var successfulDecisions = context.RelatedDecisions.Where(d => d.Successful).ToList();
if (successfulDecisions.Any())
{
Console.WriteLine("Found successful patterns:");
foreach (var decision in successfulDecisions.Take(3))
{
Console.WriteLine($" - {decision.Summary} (Relevance: {decision.Relevance:P})");
}
}
// Store insight about this analysis
await contextService.StoreLearningInsightAsync(
insight: "UserService has complex database access patterns that could benefit from caching",
category: "performance-analysis",
filePath: @"C:\MyProject\Services\UserService.cs",
metadata: new Dictionary
{
["analysisTimestamp"] = DateTime.UtcNow,
["complexityScore"] = 0.85,
["recommendedPattern"] = "cache-aside"
}
);
```
### Security Validation
```csharp
var securityService = serviceProvider.GetRequiredService();
// Validate file access
string filePath = @"C:\MyProject\Services\UserService.cs";
if (!securityService.IsPathSafe(filePath))
{
throw new SecurityException("PathValidation", filePath, "File path is not safe");
}
if (!securityService.IsFileAllowed(filePath))
{
throw new SecurityException("FileAccess", filePath, "File access not allowed");
}
// Sanitize user input
string userQuery = securityService.SanitizeInput(rawUserInput);
// Validate configuration
var config = serviceProvider.GetRequiredService>().Value;
var validationResult = securityService.ValidateConfiguration(config);
if (!validationResult.IsValid)
{
foreach (var error in validationResult.Errors)
{
Console.WriteLine($"Configuration error: {error}");
}
}
```
### Error Handling
```csharp
try
{
var result = await orchestrator.ExecuteCompleteLearningSessionAsync(session);
}
catch (CompilationException ex)
{
Console.WriteLine($"Compilation failed: {ex.ErrorCount} errors, {ex.WarningCount} warnings");
foreach (var error in ex.Errors.Take(5))
{
Console.WriteLine($" - {error}");
}
}
catch (SecurityException ex)
{
Console.WriteLine($"Security violation in {ex.ValidationType}: {ex.Message}");
// Log security incident
}
catch (AIServiceException ex)
{
Console.WriteLine($"AI service {ex.ServiceName} failed: {ex.Message}");
if (ex.IsRetryable)
{
Console.WriteLine("This operation can be retried");
}
}
catch (LearningException ex)
{
Console.WriteLine($"Learning operation failed in {ex.OperationContext}: {ex.Message}");
Console.WriteLine($"Correlation ID: {ex.CorrelationId}");
}
```
### Plugin Usage
```csharp
// Using the main learning plugin
var plugin = new ComprehensiveLearningRefactorPlugin();
var parameters = new Dictionary
{
["solutionPath"] = @"C:\MyProject\Solution.sln",
["learningMode"] = "aggressive",
["enableSemanticSearch"] = true,
["openAIApiKey"] = Environment.GetEnvironmentVariable("OPENAI_API_KEY"),
["maxIterations"] = 30,
["sessionTimeoutMinutes"] = 120,
["verboseReporting"] = true
};
var result = await plugin.ExecuteAsync(parameters);
if (result.Success)
{
var learningResult = (ComprehensiveLearningResult)result.Data;
Console.WriteLine($"Learning session completed successfully");
Console.WriteLine($"Project: {learningResult.ProjectName}");
Console.WriteLine($"Duration: {learningResult.TotalDuration}");
}
else
{
Console.WriteLine($"Learning session failed: {result.Message}");
}
```
---
**Generated on 2025-06-25 by Claude Code**
**Version**: 1.0.0
**Last Updated**: After revolutionary unified context integration