csharp4405de34 | 1 | #nullable enable |
| 2 | using System.Text.Json; |
| 3 | |
| 4 | namespace CascadeIDE.Services.AgentContract; |
| 5 | |
| 6 | /// <summary>Паритет с MCP <c>git_*</c>: тот же JSON (success, exit_code, output с усечением), что и в IDE.</summary> |
| 7 | internal static class AgentContractGitJson |
| 8 | { |
| 9 | private const int MaxOutputChars = 4000; |
| 10 | |
| 11 | private static string TruncateOutput(string? text) |
| 12 | { |
| 13 | if (string.IsNullOrEmpty(text)) |
| 14 | return ""; |
| 15 | return text.Length > MaxOutputChars ? text[..MaxOutputChars] + "\n... (output truncated)" : text; |
| 16 | } |
| 17 | |
| 18 | public static string Serialize(bool success, int exitCode, string output) => |
| 19 | JsonSerializer.Serialize(new { success, exit_code = exitCode, output = TruncateOutput(output) }); |
| 20 | |
| 21 | public static async Task<string> RunAsync( |
| 22 | IGitCommandRunner runner, |
| 23 | IReadOnlyList<string> gitArgs, |
| 24 | string workspaceRoot, |
| 25 | CancellationToken cancellationToken) |
| 26 | { |
| 27 | var result = await runner.RunAsync(gitArgs, workspaceRoot, cancellationToken).ConfigureAwait(false); |
| 28 | return Serialize(result.Success, result.ExitCode, result.Output); |
| 29 | } |
| 30 | } |
| 31 | |
View only · write via MCP/CIDE