96 lines
3.7 KiB
C#
96 lines
3.7 KiB
C#
using LazyBear.MCP.Services.Confluence;
|
|
using LazyBear.MCP.Services.GitLab;
|
|
using LazyBear.MCP.Services.Jira;
|
|
using LazyBear.MCP.Services.Kubernetes;
|
|
using LazyBear.MCP.Services.Logging;
|
|
using LazyBear.MCP.Services.Mcp;
|
|
using LazyBear.MCP.Services.ToolRegistry;
|
|
using LazyBear.MCP.TUI;
|
|
using LazyBear.MCP.TUI.Components;
|
|
using LazyBear.MCP.TUI.Localization;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Hosting;
|
|
using Microsoft.Extensions.Logging;
|
|
using RazorConsole.Core;
|
|
|
|
// ── Общий логгер и один DI-контейнер для TUI + MCP ──────────────────────────
|
|
var logSink = new InMemoryLogSink();
|
|
|
|
var host = Host.CreateDefaultBuilder(args)
|
|
.ConfigureServices(services =>
|
|
{
|
|
services.AddSingleton(logSink);
|
|
services.AddSingleton<ToolRegistryService>();
|
|
|
|
// MCP-провайдеры
|
|
services.AddSingleton<K8sClientProvider>();
|
|
services.AddSingleton<JiraClientProvider>();
|
|
services.AddSingleton<ConfluenceClientProvider>();
|
|
services.AddSingleton<GitLabClientProvider>();
|
|
|
|
// Модули инструментов (добавь новый IToolModule — он появится в TUI)
|
|
services.AddSingleton<IToolModule, JiraToolModule>();
|
|
services.AddSingleton<IToolModule, KubernetesToolModule>();
|
|
services.AddSingleton<IToolModule, ConfluenceToolModule>();
|
|
services.AddSingleton<IToolModule, GitLabToolModule>();
|
|
|
|
// HTTP MCP endpoint запускаем в фоне, чтобы TUI оставался владельцем консоли
|
|
services.AddHostedService<McpWebHostedService>();
|
|
|
|
// Глобальный читатель клавиш — единственный источник клавишных событий для TUI
|
|
services.AddSingleton<GlobalKeyboardService>();
|
|
services.AddHostedService(sp => sp.GetRequiredService<GlobalKeyboardService>());
|
|
|
|
// Локализация TUI (en/ru, переключение клавишей L)
|
|
services.AddSingleton<LocalizationService>();
|
|
})
|
|
.ConfigureLogging(logging =>
|
|
{
|
|
logging.ClearProviders();
|
|
logging.AddProvider(new InMemoryLoggerProvider(logSink));
|
|
})
|
|
.UseRazorConsole<App>(hostBuilder =>
|
|
{
|
|
hostBuilder.ConfigureServices(services =>
|
|
{
|
|
services.Configure<ConsoleAppOptions>(options =>
|
|
{
|
|
options.AutoClearConsole = true;
|
|
options.EnableTerminalResizing = true;
|
|
options.AfterRenderAsync = (_, _, _) =>
|
|
{
|
|
try
|
|
{
|
|
Console.CursorVisible = false;
|
|
}
|
|
catch
|
|
{
|
|
// Ignore terminals that do not support CursorVisible.
|
|
}
|
|
|
|
try
|
|
{
|
|
Console.Write("\u001b[?25l");
|
|
Console.Out.Flush();
|
|
}
|
|
catch
|
|
{
|
|
// Ignore terminals that do not support ANSI cursor control.
|
|
}
|
|
|
|
return Task.CompletedTask;
|
|
};
|
|
});
|
|
});
|
|
})
|
|
.Build();
|
|
|
|
// ── Регистрируем модули один раз до старта TUI и web host ───────────────────
|
|
var registry = host.Services.GetRequiredService<ToolRegistryService>();
|
|
foreach (var module in host.Services.GetServices<IToolModule>())
|
|
{
|
|
registry.RegisterModule(module);
|
|
}
|
|
|
|
await host.RunAsync();
|