using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection.Extensions; using Microsoft.Extensions.Options; using StellaOps.Scanner.EntryTrace.Diagnostics; using StellaOps.Scanner.EntryTrace.Runtime; using StellaOps.Scanner.EntryTrace.Semantic; using StellaOps.Scanner.EntryTrace.Semantic.Adapters; using StellaOps.Scanner.EntryTrace.Semantic.Analysis; namespace StellaOps.Scanner.EntryTrace; public static class ServiceCollectionExtensions { public static IServiceCollection AddEntryTraceAnalyzer(this IServiceCollection services, Action? configure = null) { if (services is null) { throw new ArgumentNullException(nameof(services)); } services.AddOptions() .BindConfiguration(EntryTraceAnalyzerOptions.SectionName); if (configure is not null) { services.Configure(configure); } services.TryAddSingleton(); services.TryAddSingleton(); services.TryAddSingleton(); services.TryAddSingleton(); return services; } /// /// Adds entry trace analyzer with integrated semantic analysis. /// /// /// Part of Sprint 0411 - Semantic Entrypoint Engine (Task 17). /// public static IServiceCollection AddSemanticEntryTraceAnalyzer( this IServiceCollection services, Action? configure = null, Action? configureSemantic = null) { if (services is null) { throw new ArgumentNullException(nameof(services)); } // Add base entry trace analyzer services.AddEntryTraceAnalyzer(configure); // Add semantic analysis options services.AddOptions() .BindConfiguration(SemanticAnalysisOptions.SectionName); if (configureSemantic is not null) { services.Configure(configureSemantic); } // Register semantic analysis components services.TryAddSingleton(); services.TryAddSingleton(); services.TryAddSingleton(); // Register language adapters services.TryAddEnumerable(ServiceDescriptor.Singleton()); services.TryAddEnumerable(ServiceDescriptor.Singleton()); services.TryAddEnumerable(ServiceDescriptor.Singleton()); services.TryAddEnumerable(ServiceDescriptor.Singleton()); services.TryAddEnumerable(ServiceDescriptor.Singleton()); // Register orchestrator services.TryAddSingleton(sp => { var adapters = sp.GetServices().ToList(); var capabilityDetector = sp.GetRequiredService(); var threatInferrer = sp.GetRequiredService(); var boundaryMapper = sp.GetRequiredService(); return new SemanticEntrypointOrchestrator(adapters, capabilityDetector, threatInferrer, boundaryMapper); }); // Register semantic entry trace analyzer services.TryAddSingleton(); return services; } } /// /// Options for semantic analysis behavior. /// public sealed class SemanticAnalysisOptions { public const string SectionName = "Scanner:EntryTrace:Semantic"; /// Whether semantic analysis is enabled. public bool Enabled { get; set; } = true; /// Minimum confidence threshold for threat vectors (0.0-1.0). public double ThreatConfidenceThreshold { get; set; } = 0.3; /// Maximum number of threat vectors to emit per entrypoint. public int MaxThreatVectors { get; set; } = 50; /// Whether to include low-confidence capabilities. public bool IncludeLowConfidenceCapabilities { get; set; } = false; /// Languages to include in semantic analysis (empty = all). public IReadOnlyList EnabledLanguages { get; set; } = Array.Empty(); }