| 1 | using CascadeIDE.Services; |
| 2 | |
| 3 | namespace CascadeIDE.Features.Agent.Environment; |
| 4 | |
| 5 | /// <summary>Сбор <c>.cs</c> из git diff (shared diagnose.files / test.scoped).</summary> |
| 6 | internal static class AgentGitDirtyCsPaths |
| 7 | { |
| 8 | public static async Task<IReadOnlyList<string>> CollectAsync( |
| 9 | IGitCommandRunner git, |
| 10 | string workspaceRoot, |
| 11 | int maxFiles, |
| 12 | CancellationToken cancellationToken = default) |
| 13 | { |
| 14 | var wsFull = Path.GetFullPath(workspaceRoot.TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar)); |
| 15 | var unstaged = await GitNameOnlyAsync(git, wsFull, ["diff", "--name-only"], cancellationToken).ConfigureAwait(false); |
| 16 | var staged = await GitNameOnlyAsync(git, wsFull, ["diff", "--name-only", "--cached"], cancellationToken).ConfigureAwait(false); |
| 17 | var relCs = AgentDiagnoseFilesCsScopeParser.MergeGitNameOnlyOutputs(unstaged, staged); |
| 18 | |
| 19 | var cap = Math.Max(1, maxFiles); |
| 20 | var result = new List<string>(); |
| 21 | foreach (var rel in relCs) |
| 22 | { |
| 23 | if (result.Count >= cap) |
| 24 | break; |
| 25 | |
| 26 | if (!AgentDiagnoseFilesCsScopeParser.TryResolveWorkspaceCs(wsFull, rel, out var full)) |
| 27 | continue; |
| 28 | |
| 29 | result.Add(full); |
| 30 | } |
| 31 | |
| 32 | return result; |
| 33 | } |
| 34 | |
| 35 | private static async Task<string?> GitNameOnlyAsync( |
| 36 | IGitCommandRunner git, |
| 37 | string workingDirectory, |
| 38 | IReadOnlyList<string> gitArgsTail, |
| 39 | CancellationToken cancellationToken) |
| 40 | { |
| 41 | var args = new List<string> { "-c", "core.quotepath=false" }; |
| 42 | args.AddRange(gitArgsTail); |
| 43 | var (ok, _, output) = await git.RunAsync(args, workingDirectory, cancellationToken).ConfigureAwait(false); |
| 44 | return ok ? output : null; |
| 45 | } |
| 46 | } |
| 47 | |