Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 59 additions & 38 deletions src/common/Configuration/KnownSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ public static class KnownSettings
// Anthropic settings
public const string AnthropicApiKey = "Anthropic.ApiKey";
public const string AnthropicModelName = "Anthropic.ModelName";

// AWS Bedrock settings
public const string AWSBedrockAccessKey = "AWS.Bedrock.AccessKey";
public const string AWSBedrockSecretKey = "AWS.Bedrock.SecretKey";
public const string AWSBedrockRegion = "AWS.Bedrock.Region";
public const string AWSBedrockModelId = "AWS.Bedrock.ModelId";

// Google Gemini settings
public const string GoogleGeminiApiKey = "Google.Gemini.ApiKey";
public const string GoogleGeminiModelId = "Google.Gemini.ModelId";
Expand All @@ -33,15 +33,19 @@ public static class KnownSettings
public const string AzureOpenAIApiKey = "Azure.OpenAI.ApiKey";
public const string AzureOpenAIEndpoint = "Azure.OpenAI.Endpoint";
public const string AzureOpenAIChatDeployment = "Azure.OpenAI.ChatDeployment";

// OpenAI settings
public const string OpenAIApiKey = "OpenAI.ApiKey";
public const string OpenAIEndpoint = "OpenAI.Endpoint";
public const string OpenAIChatModelName = "OpenAI.ChatModelName";


//Ollama settings
public const string OllamaBaseUrl = "Ollama.BaseUrl";
public const string OllamaModelId = "Ollama.ModelId";

// GitHub settings
public const string GitHubToken = "GitHub.Token";

// Copilot settings
public const string CopilotModelName = "Copilot.ModelName";
public const string CopilotApiEndpoint = "Copilot.ApiEndpoint";
Expand All @@ -59,11 +63,11 @@ public static class KnownSettings
public const string AppChatCompletionTimeout = "App.ChatCompletionTimeout";
public const string AppAutoApprove = "App.AutoApprove";
public const string AppAutoDeny = "App.AutoDeny";

#endregion

#region Secret Settings

/// <summary>
/// Collection of known setting names that should be treated as secrets.
/// </summary>
Expand Down Expand Up @@ -91,11 +95,11 @@ public static class KnownSettings
// GitHub secrets
GitHubToken,
};

#endregion

#region Setting Format Mappings

/// <summary>
/// Mapping from dot notation to environment variable format.
/// </summary>
Expand Down Expand Up @@ -129,6 +133,10 @@ public static class KnownSettings
{ OpenAIApiKey, "OPENAI_API_KEY" },
{ OpenAIEndpoint, "OPENAI_ENDPOINT" },
{ OpenAIChatModelName, "OPENAI_CHAT_MODEL_NAME" },

//Ollama mappings
{ OllamaBaseUrl, "OLLAMA_BASE_URL" },
{ OllamaModelId, "OLLAMA_MODEL_ID" },

// GitHub mappings
{ GitHubToken, "GITHUB_TOKEN" },
Expand All @@ -151,7 +159,7 @@ public static class KnownSettings
{ AppAutoApprove, "CYCOD_AUTO_APPROVE" },
{ AppAutoDeny, "CYCOD_AUTO_DENY" }
};

/// <summary>
/// Mapping from dot notation to CLI option format.
/// </summary>
Expand Down Expand Up @@ -185,6 +193,10 @@ public static class KnownSettings
{ OpenAIApiKey, "--openai-api-key" },
{ OpenAIEndpoint, "--openai-endpoint" },
{ OpenAIChatModelName, "--openai-chat-model-name" },

// Ollama mappings
{ OllamaBaseUrl, "--ollama-base-url" },
{ OllamaModelId, "--ollama-model-id" },

// GitHub mappings
{ GitHubToken, "--github-token" },
Expand All @@ -206,12 +218,12 @@ public static class KnownSettings
{ AppAutoApprove, "--auto-approve" },
{ AppAutoDeny, "--auto-deny" }
};

/// <summary>
/// Mapping from environment variable format to dot notation.
/// </summary>
private static readonly Dictionary<string, string> _envVarToDotMap;

/// <summary>
/// Mapping from CLI option format to dot notation.
/// </summary>
Expand All @@ -237,7 +249,7 @@ public static class KnownSettings
AnthropicApiKey,
AnthropicModelName
};

/// <summary>
/// Collection of settings for AWS Bedrock integration.
/// </summary>
Expand All @@ -248,7 +260,7 @@ public static class KnownSettings
AWSBedrockRegion,
AWSBedrockModelId
};

/// <summary>
/// Collection of settings for Google Gemini integration.
/// </summary>
Expand All @@ -257,7 +269,7 @@ public static class KnownSettings
GoogleGeminiApiKey,
GoogleGeminiModelId
};

/// <summary>
/// Collection of settings for Grok integration.
/// </summary>
Expand All @@ -277,7 +289,7 @@ public static class KnownSettings
AzureOpenAIEndpoint,
AzureOpenAIChatDeployment
};

/// <summary>
/// Collection of settings for OpenAI integration.
/// </summary>
Expand All @@ -287,15 +299,24 @@ public static class KnownSettings
OpenAIEndpoint,
OpenAIChatModelName
};


/// <summary>
/// Collection of settings for Ollama integration.
/// </summary>
public static readonly HashSet<string> OllamaSettings = new(StringComparer.OrdinalIgnoreCase)
{
OllamaBaseUrl,
OllamaModelId
};

/// <summary>
/// Collection of settings for GitHub integration.
/// </summary>
public static readonly HashSet<string> GitHubSettings = new(StringComparer.OrdinalIgnoreCase)
{
GitHubToken
};

/// <summary>
/// Collection of settings for Copilot integration.
/// </summary>
Expand All @@ -306,7 +327,7 @@ public static class KnownSettings
CopilotIntegrationId,
CopilotEditorVersion
};

/// <summary>
/// Collection of settings for application configuration.
/// </summary>
Expand All @@ -323,16 +344,16 @@ public static class KnownSettings
AppAutoApprove,
AppAutoDeny
};

#endregion

static KnownSettings()
{
// Initialize reverse mappings
_envVarToDotMap = _dotToEnvVarMap.ToDictionary(kvp => kvp.Value, kvp => kvp.Key, StringComparer.OrdinalIgnoreCase);
_cliOptionToDotMap = _dotToCLIOptionMap.ToDictionary(kvp => kvp.Value, kvp => kvp.Key, StringComparer.OrdinalIgnoreCase);
}

/// <summary>
/// Checks if the given key is a known setting.
/// </summary>
Expand All @@ -345,7 +366,7 @@ public static bool IsKnown(string key)
if (_cliOptionToDotMap.ContainsKey(key)) return true;
return false;
}

/// <summary>
/// Checks if the given key is a secret value that should be obfuscated.
/// </summary>
Expand All @@ -356,7 +377,7 @@ public static bool IsSecret(string key)
var dotNotationKey = ToDotNotation(key);
return _secretSettings.Contains(dotNotationKey);
}

/// <summary>
/// Gets all known setting names in dot notation format.
/// </summary>
Expand All @@ -376,7 +397,7 @@ public static bool IsMultiValue(string key)
var dotNotationKey = ToDotNotation(key);
return _multiValueSettings.Contains(dotNotationKey, StringComparer.OrdinalIgnoreCase);
}

/// <summary>
/// Gets the canonical form of a known setting key.
/// </summary>
Expand Down Expand Up @@ -418,7 +439,7 @@ public static string ToEnvironmentVariable(string key)
// Otherwise, just return it
return key;
}

/// <summary>
/// Converts a setting name to CLI option format.
/// </summary>
Expand All @@ -427,20 +448,20 @@ public static string ToEnvironmentVariable(string key)
public static string ToCLIOption(string key)
{
if (IsCLIOptionFormat(key)) return key;

// Try to map to a CLI option
var dotNotationKey = ToDotNotation(key);
if (_dotToCLIOptionMap.TryGetValue(dotNotationKey, out string? cliOption))
{
return cliOption;
}

// Otherwise, use a general algorithm
var parts = dotNotationKey.Split('.');
var kebabParts = parts.Select(p => ToKebabCase(p));
return "--" + string.Join("-", kebabParts).ToLowerInvariant();
}

/// <summary>
/// Converts a setting name to dot notation format.
/// </summary>
Expand All @@ -456,15 +477,15 @@ public static string ToDotNotation(string key)
return dotNotation;
}
}

// If it's a CLI option format
if (IsCLIOptionFormat(key))
{
if (_cliOptionToDotMap.TryGetValue(key, out string? dotNotation))
{
return dotNotation;
}

// Remove leading -- and convert kebab-case to PascalCase with dots
var trimmed = key.TrimStart('-');
var parts = trimmed.Split('-');
Expand All @@ -475,13 +496,13 @@ public static string ToDotNotation(string key)
parts[i] = char.ToUpper(parts[i][0]) + parts[i].Substring(1).ToLower();
}
}

return string.Join(".", parts);
}

return key;
}

/// <summary>
/// Determines if the given key is in environment variable format.
/// </summary>
Expand All @@ -491,7 +512,7 @@ public static bool IsEnvironmentVariableFormat(string key)
{
return Regex.IsMatch(key, "^[A-Z0-9_]+$");
}

/// <summary>
/// Determines if the given key is in CLI option format.
/// </summary>
Expand All @@ -501,7 +522,7 @@ public static bool IsCLIOptionFormat(string key)
{
return key.StartsWith("--");
}

/// <summary>
/// Converts a string from PascalCase to kebab-case.
/// </summary>
Expand All @@ -511,7 +532,7 @@ private static string ToKebabCase(string input)
{
if (string.IsNullOrEmpty(input))
return input;

// Insert a hyphen before each uppercase letter that follows a lowercase letter
var result = Regex.Replace(input, "(?<!^)([A-Z])", "-$1");
return result.ToLowerInvariant();
Expand Down
Loading