Files
gitcommiteditor/Plugins/GitDiagnosticPlugin.cs

93 lines
2.9 KiB
C#
Executable File

using MarketAlly.AIPlugin;
namespace MarketAlly.GitCommitEditor.Plugins;
/// <summary>
/// Risk level for git fix operations
/// </summary>
public enum RiskLevel
{
/// <summary>Safe operation, no data loss risk</summary>
Low,
/// <summary>Some risk, review before executing</summary>
Medium,
/// <summary>Potential data loss, use with caution</summary>
High
}
/// <summary>
/// Result model for git issue diagnosis
/// </summary>
public class GitDiagnosisResult
{
/// <summary>
/// Short summary of the problem (1-2 sentences)
/// </summary>
public string Problem { get; set; } = string.Empty;
/// <summary>
/// Explanation of why this happened
/// </summary>
public string Cause { get; set; } = string.Empty;
/// <summary>
/// The recommended fix command(s) to run
/// </summary>
public string FixCommand { get; set; } = string.Empty;
/// <summary>
/// Warning about potential data loss or side effects (if any)
/// </summary>
public string Warning { get; set; } = string.Empty;
/// <summary>
/// Risk level of the fix operation
/// </summary>
public RiskLevel RiskLevel { get; set; } = RiskLevel.Low;
}
/// <summary>
/// AI Plugin that the AI calls to return the git diagnosis
/// </summary>
[AIPlugin("ReturnGitDiagnosis", "Returns the diagnosis of a git issue with the problem summary, cause, fix command, and any warnings.")]
public class ReturnGitDiagnosisPlugin : IAIPlugin
{
[AIParameter("Short summary of the problem (1-2 sentences)", required: true)]
public string Problem { get; set; } = string.Empty;
[AIParameter("Explanation of why this happened", required: true)]
public string Cause { get; set; } = string.Empty;
[AIParameter("The exact git command(s) to fix the issue. Use newlines to separate multiple commands.", required: true)]
public string FixCommand { get; set; } = string.Empty;
[AIParameter("Warning about potential data loss or side effects. Leave empty if no warnings.", required: false)]
public string Warning { get; set; } = string.Empty;
[AIParameter("Risk level of the fix operation", required: true)]
public RiskLevel RiskLevel { get; set; } = RiskLevel.Low;
public IReadOnlyDictionary<string, Type> SupportedParameters => new Dictionary<string, Type>
{
["problem"] = typeof(string),
["cause"] = typeof(string),
["fixCommand"] = typeof(string),
["warning"] = typeof(string),
["riskLevel"] = typeof(RiskLevel)
};
public Task<AIPluginResult> ExecuteAsync(IReadOnlyDictionary<string, object> parameters)
{
var result = new GitDiagnosisResult
{
Problem = Problem,
Cause = Cause,
FixCommand = FixCommand,
Warning = Warning ?? string.Empty,
RiskLevel = RiskLevel
};
return Task.FromResult(new AIPluginResult(result, "Git diagnosis returned"));
}
}