181 lines
6.0 KiB
C#
Executable File
181 lines
6.0 KiB
C#
Executable File
using System.Text.Json;
|
|
|
|
namespace MarketAlly.AIPlugin.ClaudeCode;
|
|
|
|
/// <summary>
|
|
/// Main service interface for Claude Code integration
|
|
/// </summary>
|
|
public interface IClaudeCodeService
|
|
{
|
|
/// <summary>
|
|
/// Sends a chat message to Claude Code and gets a response
|
|
/// </summary>
|
|
/// <param name="request">The chat request</param>
|
|
/// <param name="cancellationToken">Cancellation token</param>
|
|
/// <returns>Claude's response</returns>
|
|
Task<ClaudeCodeResponse<string>> SendChatMessageAsync(ChatRequest request, CancellationToken cancellationToken = default);
|
|
|
|
/// <summary>
|
|
/// Analyzes a file or code snippet
|
|
/// </summary>
|
|
/// <param name="request">The analysis request</param>
|
|
/// <param name="cancellationToken">Cancellation token</param>
|
|
/// <returns>Analysis results</returns>
|
|
Task<ClaudeCodeResponse<AnalysisResult>> AnalyzeCodeAsync(AnalysisRequest request, CancellationToken cancellationToken = default);
|
|
|
|
/// <summary>
|
|
/// Gets current rate limit status
|
|
/// </summary>
|
|
/// <param name="cancellationToken">Cancellation token</param>
|
|
/// <returns>Rate limit information</returns>
|
|
Task<ClaudeCodeResponse<RateLimitInfo>> GetRateLimitStatusAsync(CancellationToken cancellationToken = default);
|
|
|
|
/// <summary>
|
|
/// Searches project context for relevant information
|
|
/// </summary>
|
|
/// <param name="query">Search query</param>
|
|
/// <param name="projectPath">Project path</param>
|
|
/// <param name="cancellationToken">Cancellation token</param>
|
|
/// <returns>Search results</returns>
|
|
Task<ClaudeCodeResponse<List<ContextSearchResult>>> SearchContextAsync(string query, string? projectPath = null, CancellationToken cancellationToken = default);
|
|
|
|
/// <summary>
|
|
/// Stores a decision or insight for future reference
|
|
/// </summary>
|
|
/// <param name="request">The decision storage request</param>
|
|
/// <param name="cancellationToken">Cancellation token</param>
|
|
/// <returns>Success response</returns>
|
|
Task<ClaudeCodeResponse<bool>> StoreDecisionAsync(StoreDecisionRequest request, CancellationToken cancellationToken = default);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Chat request model
|
|
/// </summary>
|
|
public class ChatRequest
|
|
{
|
|
public string Message { get; set; } = string.Empty;
|
|
public string? SessionId { get; set; }
|
|
public string? ProjectPath { get; set; }
|
|
public Dictionary<string, object>? Context { get; set; }
|
|
public bool IncludeProjectContext { get; set; } = true;
|
|
public bool IncludeHistory { get; set; } = true;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Analysis request model
|
|
/// </summary>
|
|
public class AnalysisRequest
|
|
{
|
|
public string? FilePath { get; set; }
|
|
public string? Code { get; set; }
|
|
public string AnalysisType { get; set; } = "general"; // general, security, performance, documentation
|
|
public string? ProjectPath { get; set; }
|
|
public Dictionary<string, object>? Options { get; set; }
|
|
}
|
|
|
|
/// <summary>
|
|
/// Store decision request model
|
|
/// </summary>
|
|
public class StoreDecisionRequest
|
|
{
|
|
public string Decision { get; set; } = string.Empty;
|
|
public string Category { get; set; } = "decision";
|
|
public string? ProjectPath { get; set; }
|
|
public Dictionary<string, object>? Metadata { get; set; }
|
|
}
|
|
|
|
/// <summary>
|
|
/// Analysis result model
|
|
/// </summary>
|
|
public class AnalysisResult
|
|
{
|
|
public string Summary { get; set; } = string.Empty;
|
|
public List<AnalysisIssue> Issues { get; set; } = new();
|
|
public List<AnalysisRecommendation> Recommendations { get; set; } = new();
|
|
public Dictionary<string, object> Metrics { get; set; } = new();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Analysis issue model
|
|
/// </summary>
|
|
public class AnalysisIssue
|
|
{
|
|
public string Type { get; set; } = string.Empty;
|
|
public string Severity { get; set; } = string.Empty;
|
|
public string Description { get; set; } = string.Empty;
|
|
public string? Line { get; set; }
|
|
public string? File { get; set; }
|
|
}
|
|
|
|
/// <summary>
|
|
/// Analysis recommendation model
|
|
/// </summary>
|
|
public class AnalysisRecommendation
|
|
{
|
|
public string Title { get; set; } = string.Empty;
|
|
public string Description { get; set; } = string.Empty;
|
|
public string Priority { get; set; } = string.Empty;
|
|
public List<string> ActionItems { get; set; } = new();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Context search result model
|
|
/// </summary>
|
|
public class ContextSearchResult
|
|
{
|
|
public string Id { get; set; } = string.Empty;
|
|
public string Type { get; set; } = string.Empty;
|
|
public string Content { get; set; } = string.Empty;
|
|
public DateTime Timestamp { get; set; }
|
|
public double Relevance { get; set; }
|
|
public Dictionary<string, object> Metadata { get; set; } = new();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Rate limit information model
|
|
/// </summary>
|
|
public class RateLimitInfo
|
|
{
|
|
public string Tier { get; set; } = string.Empty;
|
|
public int Current { get; set; }
|
|
public int Limit { get; set; }
|
|
public DateTime ResetTime { get; set; }
|
|
public TimeSpan TimeToReset { get; set; }
|
|
public double PercentageUsed { get; set; }
|
|
public bool IsNearLimit { get; set; }
|
|
}
|
|
|
|
/// <summary>
|
|
/// Generic response wrapper for Claude Code operations
|
|
/// </summary>
|
|
/// <typeparam name="T">Response data type</typeparam>
|
|
public class ClaudeCodeResponse<T>
|
|
{
|
|
public bool Success { get; set; }
|
|
public T? Data { get; set; }
|
|
public string? Error { get; set; }
|
|
public string? ErrorCode { get; set; }
|
|
public RateLimitInfo? RateLimitInfo { get; set; }
|
|
public Dictionary<string, object> Metadata { get; set; } = new();
|
|
|
|
public static ClaudeCodeResponse<T> CreateSuccess(T data, RateLimitInfo? rateLimitInfo = null)
|
|
{
|
|
return new ClaudeCodeResponse<T>
|
|
{
|
|
Success = true,
|
|
Data = data,
|
|
RateLimitInfo = rateLimitInfo
|
|
};
|
|
}
|
|
|
|
public static ClaudeCodeResponse<T> CreateError(string error, string? errorCode = null, RateLimitInfo? rateLimitInfo = null)
|
|
{
|
|
return new ClaudeCodeResponse<T>
|
|
{
|
|
Success = false,
|
|
Error = error,
|
|
ErrorCode = errorCode,
|
|
RateLimitInfo = rateLimitInfo
|
|
};
|
|
}
|
|
} |