| 1 | using CascadeIDE.Services; |
| 2 | |
| 3 | namespace CascadeIDE.Features.IdeMcp.Execution; |
| 4 | |
| 5 | /// <summary>Хендлеры agent-notes.</summary> |
| 6 | internal sealed partial class IdeMcpCommandExecutor |
| 7 | { |
| 8 | private void RegisterAgentNotes(Action<string, Handler> add) |
| 9 | { |
| 10 | add(Services.IdeCommands.WriteAgentNotes, async (args, ct) => await _actions.WriteAgentNotesAsync(McpCommandJsonArgs.String(args, "content") ?? "", ct)); |
| 11 | add(Services.IdeCommands.ReadAgentNotes, async (_, ct) => await _actions.ReadAgentNotesAsync(ct)); |
| 12 | add(Services.IdeCommands.AppendAgentNotes, async (args, ct) => await _actions.AppendAgentNotesAsync(McpCommandJsonArgs.String(args, "content") ?? "", ct)); |
| 13 | add(Services.IdeCommands.ListAgentNotesRevisions, async (args, ct) => |
| 14 | await _actions.ListAgentNotesRevisionsAsync(args is not null && args.TryGetValue("limit", out var l) && l.TryGetInt32(out var v) ? v : null, ct)); |
| 15 | add(Services.IdeCommands.RollbackAgentNotes, async (args, ct) => |
| 16 | await _actions.RollbackAgentNotesAsync(McpCommandJsonArgs.String(args, "revision_file"), ct)); |
| 17 | add(Services.IdeCommands.ReadHotContext, async (args, ct) => |
| 18 | await _actions.ReadHotContextAsync(McpCommandJsonArgs.String(args, "active_scope"), ct)); |
| 19 | add(Services.IdeCommands.RouteContext, async (args, ct) => |
| 20 | await _actions.RouteContextAsync( |
| 21 | McpCommandJsonArgs.String(args, "query") ?? "", |
| 22 | McpCommandJsonArgs.String(args, "active_scope"), |
| 23 | args is not null && args.TryGetValue("max_sections", out var ms) && ms.TryGetInt32(out var msv) ? msv : null, |
| 24 | args is not null && args.TryGetValue("max_chars", out var mc) && mc.TryGetInt32(out var mcv) ? mcv : null, |
| 25 | ct)); |
| 26 | add(Services.IdeCommands.MemoryHealth, async (args, ct) => |
| 27 | await _actions.MemoryHealthAsync(McpCommandJsonArgs.String(args, "active_scope"), ct)); |
| 28 | add(Services.IdeCommands.CompactHotContext, async (args, ct) => |
| 29 | await _actions.CompactHotContextAsync(McpCommandJsonArgs.Bool(args, "apply"), ct)); |
| 30 | add(Services.IdeCommands.ExtractFromArchive, async (args, ct) => |
| 31 | await _actions.ExtractFromArchiveAsync( |
| 32 | McpCommandJsonArgs.String(args, "query") ?? "", |
| 33 | McpCommandJsonArgs.String(args, "revision_file"), |
| 34 | args is not null && args.TryGetValue("head_limit", out var hl) && hl.TryGetInt32(out var hlv) ? hlv : null, |
| 35 | args is not null && args.TryGetValue("context_lines", out var cl) && cl.TryGetInt32(out var clv) ? clv : null, |
| 36 | ct)); |
| 37 | add(Services.IdeCommands.UpsertAgentNotesSection, async (args, ct) => |
| 38 | await _actions.UpsertAgentNotesSectionAsync(McpCommandJsonArgs.String(args, "section_id") ?? "", McpCommandJsonArgs.String(args, "content") ?? "", ct)); |
| 39 | add(Services.IdeCommands.SearchAgentNotes, async (args, ct) => |
| 40 | await _actions.SearchAgentNotesAsync(McpCommandJsonArgs.String(args, "query") ?? "", args is not null && args.TryGetValue("head_limit", out var hl) && hl.TryGetInt32(out var v) ? v : null, ct)); |
| 41 | add(Services.IdeCommands.ReadKnowledgeFile, async (args, ct) => |
| 42 | await _actions.ReadKnowledgeFileAsync( |
| 43 | McpCommandJsonArgs.String(args, "file_path") ?? "", |
| 44 | McpCommandJsonArgs.OptionalInt32(args, "offset"), |
| 45 | McpCommandJsonArgs.OptionalInt32(args, "limit"), |
| 46 | McpCommandJsonArgs.KnowledgeRootId(args), |
| 47 | ct)); |
| 48 | add(Services.IdeCommands.ListKnowledgeFiles, async (args, ct) => |
| 49 | await _actions.ListKnowledgeFilesAsync( |
| 50 | McpCommandJsonArgs.String(args, "subdir"), |
| 51 | McpCommandJsonArgs.KnowledgeRootId(args), |
| 52 | ct)); |
| 53 | add(Services.IdeCommands.WriteKnowledgeFile, async (args, ct) => |
| 54 | await _actions.WriteKnowledgeFileAsync( |
| 55 | McpCommandJsonArgs.String(args, "file_path") ?? "", |
| 56 | McpCommandJsonArgs.String(args, "content") ?? "", |
| 57 | McpCommandJsonArgs.KnowledgePath(args), |
| 58 | McpCommandJsonArgs.Bool(args, "save_revision", true), |
| 59 | McpCommandJsonArgs.KnowledgeRootId(args), |
| 60 | ct)); |
| 61 | add(Services.IdeCommands.AppendKnowledgeFile, async (args, ct) => |
| 62 | await _actions.AppendKnowledgeFileAsync( |
| 63 | McpCommandJsonArgs.String(args, "file_path") ?? "", |
| 64 | McpCommandJsonArgs.String(args, "content") ?? "", |
| 65 | McpCommandJsonArgs.KnowledgePath(args), |
| 66 | McpCommandJsonArgs.Bool(args, "save_revision", true), |
| 67 | McpCommandJsonArgs.KnowledgeRootId(args), |
| 68 | ct)); |
| 69 | add(Services.IdeCommands.UpsertKnowledgeSection, async (args, ct) => |
| 70 | await _actions.UpsertKnowledgeSectionAsync( |
| 71 | McpCommandJsonArgs.String(args, "file_path") ?? "", |
| 72 | McpCommandJsonArgs.String(args, "section_id") ?? "", |
| 73 | McpCommandJsonArgs.String(args, "content") ?? "", |
| 74 | McpCommandJsonArgs.KnowledgePath(args), |
| 75 | McpCommandJsonArgs.Bool(args, "save_revision", true), |
| 76 | McpCommandJsonArgs.KnowledgeRootId(args), |
| 77 | ct)); |
| 78 | add(Services.IdeCommands.DeleteKnowledgeFile, async (args, ct) => |
| 79 | await _actions.DeleteKnowledgeFileAsync( |
| 80 | McpCommandJsonArgs.String(args, "file_path") ?? "", |
| 81 | McpCommandJsonArgs.KnowledgePath(args), |
| 82 | McpCommandJsonArgs.KnowledgeRootId(args), |
| 83 | ct)); |
| 84 | add(Services.IdeCommands.DeleteKnowledgeSection, async (args, ct) => |
| 85 | await _actions.DeleteKnowledgeSectionAsync( |
| 86 | McpCommandJsonArgs.String(args, "file_path") ?? "", |
| 87 | McpCommandJsonArgs.String(args, "section_id") ?? "", |
| 88 | McpCommandJsonArgs.KnowledgePath(args), |
| 89 | McpCommandJsonArgs.KnowledgeRootId(args), |
| 90 | ct)); |
| 91 | } |
| 92 | } |
| 93 | |