| 1 | using CascadeIDE.Models; |
| 2 | |
| 3 | namespace CascadeIDE.Services; |
| 4 | |
| 5 | /// <summary> |
| 6 | /// Подставляет заводские строковые дефолты, если в пользовательском TOML поле было явно пустым |
| 7 | /// (merge не перезаписывает дефолт, но <c>""</c> из старого файла — да). |
| 8 | /// </summary> |
| 9 | public static class SettingsLegacyStringDefaults |
| 10 | { |
| 11 | public static void Apply(CascadeIdeSettings settings) |
| 12 | { |
| 13 | ApplyIntercomTransport(settings.Intercom.Transport); |
| 14 | ApplyHybridIndex(settings.HybridIndex); |
| 15 | ApplyWorkspace(settings.Workspace); |
| 16 | ApplyLanguages(settings.Languages); |
| 17 | ApplyAi(settings.Ai); |
| 18 | ApplyMcp(settings.Mcp); |
| 19 | ApplyAgentNotes(settings.AgentNotes); |
| 20 | ApplyAgentEnvironment(settings.Agent.Environment); |
| 21 | ApplyCodeNavigationMap(settings.CodeNavigationMap); |
| 22 | ApplyMarkdown(settings.Markdown); |
| 23 | } |
| 24 | |
| 25 | private static void ApplyIntercomTransport(IntercomTransportSettings t) |
| 26 | { |
| 27 | if (string.IsNullOrWhiteSpace(t.BaseUrl)) |
| 28 | t.BaseUrl = IntercomTransportSettings.DefaultBaseUrl; |
| 29 | if (string.IsNullOrWhiteSpace(t.LocalServerPath)) |
| 30 | t.LocalServerPath = IntercomTransportSettings.DefaultLocalServerRelativePath; |
| 31 | if (string.IsNullOrWhiteSpace(t.OAuthProvider)) |
| 32 | t.OAuthProvider = "github"; |
| 33 | } |
| 34 | |
| 35 | private static void ApplyHybridIndex(HybridIndexSettings h) |
| 36 | { |
| 37 | if (string.IsNullOrWhiteSpace(h.IndexDir)) |
| 38 | h.IndexDir = ".hybrid-codebase-index"; |
| 39 | if (string.IsNullOrWhiteSpace(h.ScopeMode)) |
| 40 | h.ScopeMode = "workspace+solution"; |
| 41 | } |
| 42 | |
| 43 | private static void ApplyWorkspace(WorkspaceSettings w) |
| 44 | { |
| 45 | if (string.IsNullOrWhiteSpace(w.Mode)) |
| 46 | w.Mode = "Flight"; |
| 47 | if (string.IsNullOrWhiteSpace(w.PrimaryWorkSurface)) |
| 48 | w.PrimaryWorkSurface = PrimaryWorkSurfaceKindExtensions.IntercomValue; |
| 49 | } |
| 50 | |
| 51 | private static void ApplyLanguages(LanguagesSettings l) |
| 52 | { |
| 53 | if (string.IsNullOrWhiteSpace(l.CSharp.Mode)) |
| 54 | l.CSharp.Mode = "OmniSharp"; |
| 55 | if (string.IsNullOrWhiteSpace(l.Markdown.Mode)) |
| 56 | l.Markdown.Mode = "Marksman"; |
| 57 | } |
| 58 | |
| 59 | private static void ApplyAi(AiSettings ai) |
| 60 | { |
| 61 | if (string.IsNullOrWhiteSpace(ai.Mode)) |
| 62 | ai.Mode = "local"; |
| 63 | if (string.IsNullOrWhiteSpace(ai.Local.Backend)) |
| 64 | ai.Local.Backend = "ollama"; |
| 65 | if (string.IsNullOrWhiteSpace(ai.Local.Ollama.Model)) |
| 66 | ai.Local.Ollama.Model = "qwen2.5-coder:7b"; |
| 67 | if (string.IsNullOrWhiteSpace(ai.Cloud.ActiveProvider)) |
| 68 | ai.Cloud.ActiveProvider = "anthropic"; |
| 69 | if (string.IsNullOrWhiteSpace(ai.Cloud.Anthropic.Model)) |
| 70 | ai.Cloud.Anthropic.Model = "claude-sonnet-4-20250514"; |
| 71 | if (string.IsNullOrWhiteSpace(ai.Cloud.OpenAi.BaseUrl)) |
| 72 | ai.Cloud.OpenAi.BaseUrl = "https://api.openai.com"; |
| 73 | if (string.IsNullOrWhiteSpace(ai.Cloud.OpenAi.Model)) |
| 74 | ai.Cloud.OpenAi.Model = "gpt-4o"; |
| 75 | if (string.IsNullOrWhiteSpace(ai.Cloud.DeepSeek.BaseUrl)) |
| 76 | ai.Cloud.DeepSeek.BaseUrl = "https://api.deepseek.com"; |
| 77 | if (string.IsNullOrWhiteSpace(ai.Cloud.DeepSeek.Model)) |
| 78 | ai.Cloud.DeepSeek.Model = "deepseek-chat"; |
| 79 | if (string.IsNullOrWhiteSpace(ai.Chat.SettingsPresentation)) |
| 80 | ai.Chat.SettingsPresentation = "mfd"; |
| 81 | } |
| 82 | |
| 83 | private static void ApplyMcp(McpSettings m) |
| 84 | { |
| 85 | if (string.IsNullOrWhiteSpace(m.ExternalServersJson)) |
| 86 | m.ExternalServersJson = "[]"; |
| 87 | } |
| 88 | |
| 89 | private static void ApplyAgentNotes(AgentNotesSettings n) |
| 90 | { |
| 91 | // Пустые config_path / kb_base_overlay_path — намеренно (встроенный KB). |
| 92 | } |
| 93 | |
| 94 | private static void ApplyAgentEnvironment(AgentEnvironmentSettings e) |
| 95 | { |
| 96 | if (string.IsNullOrWhiteSpace(e.DefaultVerifyPolicy)) |
| 97 | e.DefaultVerifyPolicy = "standard"; |
| 98 | if (string.IsNullOrWhiteSpace(e.DefaultSandboxProfile)) |
| 99 | e.DefaultSandboxProfile = "agent_ephemeral"; |
| 100 | if (string.IsNullOrWhiteSpace(e.ShellEscapeTier)) |
| 101 | e.ShellEscapeTier = "deny"; |
| 102 | } |
| 103 | |
| 104 | private static void ApplyCodeNavigationMap(CodeNavigationMapSettings m) |
| 105 | { |
| 106 | if (string.IsNullOrWhiteSpace(m.View)) |
| 107 | m.View = "list"; |
| 108 | if (string.IsNullOrWhiteSpace(m.Depth)) |
| 109 | m.Depth = CodeNavigationMapLevelKind.File; |
| 110 | if (string.IsNullOrWhiteSpace(m.DetailLevel)) |
| 111 | m.DetailLevel = "normal"; |
| 112 | if (string.IsNullOrWhiteSpace(m.RelatedGraphLayout)) |
| 113 | m.RelatedGraphLayout = CodeNavigationMapRelatedGraphLayoutKind.TopDown; |
| 114 | if (string.IsNullOrWhiteSpace(m.ControlFlowMainAxis)) |
| 115 | m.ControlFlowMainAxis = CodeNavigationMapControlFlowMainAxisKind.Auto; |
| 116 | if (string.IsNullOrWhiteSpace(m.ControlFlowGrain)) |
| 117 | m.ControlFlowGrain = CodeNavigationMapControlFlowGrainKind.Intent; |
| 118 | } |
| 119 | |
| 120 | private static void ApplyMarkdown(MarkdownSettings md) |
| 121 | { |
| 122 | if (string.IsNullOrWhiteSpace(md.Diagrams.KrokiUrl)) |
| 123 | md.Diagrams.KrokiUrl = "https://kroki.io"; |
| 124 | } |
| 125 | } |
| 126 | |