using System.Threading; using System.Threading.Tasks; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using PolyTrader.Core.Modularity; using PolyTrader.Modules.Supervisor.Services; namespace PolyTrader.Modules.Supervisor { /// /// Supervisor-Modul (docs/konzepte/KONZEPT-Modul-Supervisor.md): Analyse/Forensik über ALLE /// Module — strikt read-only (kein Handel). S-1: Dossier-Browser über Entscheidungsjournal, /// Order-Events, Trade-Log und JSONL-Logs. S-2 (OpenRouter-Agent + Tool-Registry), S-3 /// (Profile/Berichte/Counterfactual/Predictalytics) und S-4 (MCP-Light) folgen. /// public class SupervisorModule : IPolyTraderModule { public string Name => "Supervisor"; public string DbPrefix => "sup_"; public void RegisterServices(IServiceCollection services, IConfiguration configuration) { // S-1: Dossier-Beschaffung/-Aufbereitung. services.AddSingleton(); // S-2: read-only Tool-Registry + OpenRouter-Agent. Der API-Key kommt aus // POLYTRADER_OPENROUTER_KEY bzw. gitignorierter openrouter.key (getrennt vom Trading). services.AddSingleton(sp => Agent.SupervisorTools.CreateRegistry( sp.GetRequiredService(), sp.GetRequiredService(), sp.GetRequiredService(), sp.GetRequiredService(), sp.GetRequiredService())); services.AddSingleton(_ => new Agent.OpenRouterClient(new System.Net.Http.HttpClient { Timeout = TimeSpan.FromMinutes(3) })); services.AddSingleton(); // S-3: sup_-Persistenz (gespeicherte Analysen/Berichte). var conn = configuration["Database:MySqlConnectionString"] ?? string.Empty; services.AddDbContextFactory(o => o.UseMySql(conn, PolyTrader.Core.Configuration.DatabaseServerVersion.Value)); services.AddSingleton(); services.AddSingleton(); // S-3: Counterfactual-Job (abgelehnte BUYs vs. Marktausgang) + täglicher Threema-Bericht // (OPT-IN via POLYTRADER_SUPERVISOR_DAILY = Stunde 0–23). services.AddSingleton(); services.AddHostedService(); services.AddHostedService(); // S-4: MCP-Light – exponiert die read-only Tool-Registry für externe KI-Clients // (z. B. Claude Code). OPT-IN via POLYTRADER_MCP_PORT, bindet nur 127.0.0.1. services.AddHostedService(); } public void RegisterUi(IModuleUiHost host, System.IServiceProvider services) { host.RegisterView(new ModuleView { Id = "supervisor.main", Title = "Supervisor", Group = "Supervisor", Order = 300, CreateForm = () => { var form = new Ui.SupervisorMainForm(); form.Initialize(services); return form; } }); } public Task StartAsync(CancellationToken cancellationToken) => Task.CompletedTask; public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask; } }