| 1 | #nullable enable |
| 2 | using CascadeIDE.Contracts; |
| 3 | using CascadeIDE.Models; |
| 4 | |
| 5 | namespace CascadeIDE.Features.Shell.Application; |
| 6 | |
| 7 | /// <summary> |
| 8 | /// Нормализация и coercion для shell/settings reactive handlers (без сценария и I/O). |
| 9 | /// </summary> |
| 10 | [PresentationProjection] |
| 11 | public static class ShellSettingsPresentationProjection |
| 12 | { |
| 13 | public static string NormalizeExternalMcpServersJson(string? value) => |
| 14 | value ?? "[]"; |
| 15 | |
| 16 | public static string NormalizeKrokiBaseUrl(string value) => |
| 17 | string.IsNullOrWhiteSpace(value) ? "https://kroki.io" : value.Trim(); |
| 18 | |
| 19 | public static string NormalizeAiMode(string value) => |
| 20 | AiSettings.NormalizeMode(value); |
| 21 | |
| 22 | public static string NormalizeCloudProvider(string value) => |
| 23 | AiSettings.NormalizeCloudProvider(value); |
| 24 | |
| 25 | public static bool ShouldRewriteWithNormalizedValue(string original, string normalized) => |
| 26 | !string.Equals(original, normalized, StringComparison.Ordinal); |
| 27 | |
| 28 | public static string? NormalizeOptionalSecret(string value) => |
| 29 | string.IsNullOrEmpty(value) ? null : value; |
| 30 | |
| 31 | public static bool ShouldCoerceCurrentPageWhenHidden(MfdShellPage currentPage, MfdShellPage hiddenPage) => |
| 32 | currentPage == hiddenPage; |
| 33 | |
| 34 | public static bool ShouldCoerceWhenInstrumentationHidden(MfdShellPage currentPage) => |
| 35 | currentPage is MfdShellPage.Events or MfdShellPage.Tests or MfdShellPage.Hypotheses or MfdShellPage.DebugStack; |
| 36 | |
| 37 | /// <summary>Hybrid Codebase Index: <c>workspace</c> or <c>workspace+solution</c> (TOML <c>[hybrid_index].scope_mode</c>).</summary> |
| 38 | public static string NormalizeHybridIndexScopeMode(string? value) |
| 39 | { |
| 40 | var v = (value ?? "").Trim(); |
| 41 | if (string.Equals(v, "workspace", StringComparison.OrdinalIgnoreCase)) |
| 42 | return "workspace"; |
| 43 | return "workspace+solution"; |
| 44 | } |
| 45 | |
| 46 | /// <summary>Whitespace-trim для каталога индекса под корнем workspace; пустая строка = дефолт в рантайме.</summary> |
| 47 | public static string NormalizeHybridIndexDir(string? value) => |
| 48 | string.IsNullOrWhiteSpace(value) ? "" : value.Trim(); |
| 49 | } |
| 50 | |