Forge
csharpfb8e0499
1using System.Diagnostics.CodeAnalysis;
2
3namespace AgentNotes.Core;
4
5/// <summary>Process-wide settings loaded at MCP host startup (<c>--config</c>).</summary>
6public static class AgentNotesRuntime
7{
8 private static LocalSettings? s_settings;
9
10 /// <summary>Absolute path passed to <c>--config</c> at startup (MCP host).</summary>
11 public static string? ConfigFilePath { get; private set; }
12
13 public static bool IsConfigured => s_settings is not null;
14
15 public static LocalSettings Settings =>
16 s_settings ?? throw new InvalidOperationException("Local settings are not loaded. MCP 2.0 requires --config at startup.");
17
18 public static void Initialize(LocalSettings settings, string? configFilePath = null)
19 {
20 s_settings = settings ?? throw new ArgumentNullException(nameof(settings));
21 ConfigFilePath = string.IsNullOrWhiteSpace(configFilePath)
22 ? null
23 : Path.GetFullPath(configFilePath.Trim());
24 }
25
26 /// <summary>Clears loaded TOML (host reload, empty config path, or test isolation).</summary>
27 public static void ClearConfiguration()
28 {
29 s_settings = null;
30 ConfigFilePath = null;
31 }
32
33 /// <summary>Test isolation alias for <see cref="ClearConfiguration"/>.</summary>
34 public static void ResetForTests() => ClearConfiguration();
35
36 public static bool TryGetPrimaryKnowledgeRoot([NotNullWhen(true)] out string? root)
37 {
38 if (s_settings is null)
39 {
40 root = null;
41 return false;
42 }
43
44 root = s_settings.PrimaryKnowledgeRoot;
45 return true;
46 }
47}
48
View only · write via MCP/CIDE