using System.IO; using System.Linq; using System.Text.Json; using System.Text.Json.Serialization; namespace AxCopilot.Services.Agent; internal static class TaskBoardStore { private const string StoreRelativePath = ".ax/taskboard.json"; internal sealed class TaskItem { [JsonPropertyName("id")] public int Id { get; set; } [JsonPropertyName("title")] public string Title { get; set; } = ""; [JsonPropertyName("description")] public string Description { get; set; } = ""; [JsonPropertyName("status")] public string Status { get; set; } = "open"; // open | in_progress | blocked | done | stopped [JsonPropertyName("priority")] public string Priority { get; set; } = "medium"; // high | medium | low [JsonPropertyName("output")] public string Output { get; set; } = ""; [JsonPropertyName("createdAt")] public DateTime CreatedAt { get; set; } = DateTime.Now; [JsonPropertyName("updatedAt")] public DateTime UpdatedAt { get; set; } = DateTime.Now; } internal static string GetStorePath(string workFolder) => Path.Combine(workFolder, StoreRelativePath); internal static List Load(string workFolder) { var path = GetStorePath(workFolder); if (!File.Exists(path)) return []; try { var json = TextFileCodec.ReadAllText(path).Text; return JsonSerializer.Deserialize>(json) ?? []; } catch { return []; } } internal static void Save(string workFolder, List tasks) { var path = GetStorePath(workFolder); var dir = Path.GetDirectoryName(path); if (!string.IsNullOrWhiteSpace(dir) && !Directory.Exists(dir)) Directory.CreateDirectory(dir); var json = JsonSerializer.Serialize(tasks, new JsonSerializerOptions { WriteIndented = true }); File.WriteAllText(path, json, TextFileCodec.Utf8NoBom); } internal static int NextId(List tasks) => tasks.Count == 0 ? 1 : tasks.Max(t => t.Id) + 1; internal static bool IsValidStatus(string value) => value is "open" or "in_progress" or "blocked" or "done" or "stopped"; internal static bool IsValidPriority(string value) => value is "high" or "medium" or "low"; }