-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAgentProviderStatusSnapshotReader.cs
More file actions
677 lines (613 loc) · 25.7 KB
/
AgentProviderStatusSnapshotReader.cs
File metadata and controls
677 lines (613 loc) · 25.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
using System.Diagnostics;
using System.Runtime.InteropServices;
using DotPilot.Core.ChatSessions;
using Microsoft.EntityFrameworkCore;
namespace DotPilot.Core.Providers;
internal static class AgentProviderStatusSnapshotReader
{
private const string BrowserStatusSummary =
"Desktop CLI probing is unavailable in the browser automation head. Enable the provider to author its profile here.";
private const string DisabledStatusSummary = "Provider is disabled for local agent creation.";
private const string BuiltInStatusSummary = "Built in and ready for deterministic local testing.";
private const string MissingCliSummaryFormat = "{0} CLI is not installed.";
private const string ReadySummaryFormat = "{0} CLI is ready for local desktop execution.";
private const string TimedOutSummaryFormat = "{0} CLI probe timed out. Refresh status to retry.";
private const string ModelPathVariablesLabel = "Model path variables";
private const string ConfiguredModelPathLabel = "Configured model path";
private const string OpenCliActionLabel = "Open CLI";
private const string OpenCliActionSummary = "CLI detected on PATH.";
private const string InstallActionLabel = "Install";
private const string InstallActionSummary = "Install the CLI, then refresh settings.";
private const string TimedOutActionSummary = "CLI detected on PATH, but the readiness probe timed out.";
private static readonly TimeSpan ProviderProbeTimeout = TimeSpan.FromSeconds(2);
private static readonly TimeSpan CommandTimeout = TimeSpan.FromSeconds(2);
private static readonly TimeSpan RedirectDrainTimeout = TimeSpan.FromSeconds(1);
private const string VersionSeparator = "version";
private const string EmptyOutput = "";
private static readonly System.Text.CompositeFormat MissingCliSummaryCompositeFormat =
System.Text.CompositeFormat.Parse(MissingCliSummaryFormat);
private static readonly System.Text.CompositeFormat ReadySummaryCompositeFormat =
System.Text.CompositeFormat.Parse(ReadySummaryFormat);
private static readonly System.Text.CompositeFormat TimedOutSummaryCompositeFormat =
System.Text.CompositeFormat.Parse(TimedOutSummaryFormat);
private static readonly IReadOnlyList<ProviderLocalModelRecord> EmptyLocalModelRecords = Array.Empty<ProviderLocalModelRecord>();
public static async Task<IReadOnlyList<ProviderStatusProbeResult>> BuildAsync(
LocalAgentSessionDbContext dbContext,
CancellationToken cancellationToken)
{
ArgumentNullException.ThrowIfNull(dbContext);
var preferences = await dbContext.ProviderPreferences
.ToDictionaryAsync(
preference => (AgentProviderKind)preference.ProviderKind,
cancellationToken);
var localModelsByProvider = (await dbContext.ProviderLocalModels
.AsNoTracking()
.ToListAsync(cancellationToken))
.GroupBy(record => (AgentProviderKind)record.ProviderKind)
.ToDictionary(
group => group.Key,
group => (IReadOnlyList<ProviderLocalModelRecord>)group.ToArray());
var providerKinds = Enum.GetValues<AgentProviderKind>();
var probeTasks = providerKinds
.Select(providerKind => ProbeProviderAsync(
providerKind,
GetProviderPreference(providerKind, preferences),
GetLocalModels(providerKind, localModelsByProvider),
cancellationToken))
.ToArray();
var results = await Task.WhenAll(probeTasks)
.WaitAsync(cancellationToken)
.ConfigureAwait(false);
return results;
}
private static ProviderPreferenceRecord GetProviderPreference(
AgentProviderKind kind,
Dictionary<AgentProviderKind, ProviderPreferenceRecord> preferences)
{
return preferences.TryGetValue(kind, out var preference)
? preference
: new ProviderPreferenceRecord
{
ProviderKind = (int)kind,
IsEnabled = false,
LocalModelPath = null,
UpdatedAt = DateTimeOffset.MinValue,
};
}
private static IReadOnlyList<ProviderLocalModelRecord> GetLocalModels(
AgentProviderKind kind,
Dictionary<AgentProviderKind, IReadOnlyList<ProviderLocalModelRecord>> localModelsByProvider)
{
return localModelsByProvider.TryGetValue(kind, out var localModels)
? localModels
: EmptyLocalModelRecords;
}
private static async ValueTask<ProviderStatusProbeResult> BuildProviderStatusAsync(
AgentProviderKind providerKind,
ProviderPreferenceRecord preference,
IReadOnlyList<ProviderLocalModelRecord> localModels,
CancellationToken cancellationToken)
{
var isBuiltIn = providerKind.IsBuiltIn();
var commandName = providerKind.GetCommandName();
var displayName = providerKind.GetDisplayName();
var defaultModelName = isBuiltIn
? providerKind.GetDefaultModelName()
: string.Empty;
var installCommand = providerKind.GetInstallCommand();
var fallbackModels = isBuiltIn ? providerKind.GetSupportedModelNames() : [];
var providerId = AgentSessionDeterministicIdentity.CreateProviderId(commandName);
var actions = new List<ProviderActionDescriptor>();
var details = new List<ProviderDetailDescriptor>();
string? executablePath = null;
var installedVersion = isBuiltIn ? defaultModelName : (string?)null;
var suggestedModelName = defaultModelName;
var supportedModelNames = ResolveSupportedModels(
defaultModelName,
defaultModelName,
fallbackModels,
[]);
var status = AgentProviderStatus.Ready;
var statusSummary = BuiltInStatusSummary;
var canCreateAgents = isBuiltIn;
if (OperatingSystem.IsBrowser() && !isBuiltIn)
{
details.Add(new ProviderDetailDescriptor("Install command", installCommand));
actions.Add(new ProviderActionDescriptor("Install", "Run this on desktop.", installCommand, ProviderActionKind.CopyCommand));
status = AgentProviderStatus.Unsupported;
statusSummary = BrowserStatusSummary;
canCreateAgents = preference.IsEnabled;
}
else if (providerKind.IsLocalModelProvider())
{
var configuration = await LocalModelProviderConfigurationReader.ReadAsync(
providerKind,
localModels,
preference.LocalModelPath,
cancellationToken).ConfigureAwait(false);
details.Add(new ProviderDetailDescriptor(
ModelPathVariablesLabel,
string.Join(", ", configuration.EnvironmentVariableNames)));
actions.Add(new ProviderActionDescriptor(
providerKind.GetLocalModelPickerLabel(),
providerKind.GetLocalModelSetupSummary(),
string.Empty,
providerKind.GetLocalModelPickerActionKind()));
var configuredModelPaths = FormatDetailValues(configuration.ConfiguredModelPaths);
if (!string.IsNullOrWhiteSpace(configuredModelPaths))
{
details.Add(new ProviderDetailDescriptor(
configuration.ConfiguredModelPaths.Count > 1
? "Configured model paths"
: ConfiguredModelPathLabel,
configuredModelPaths));
}
var detectedRuntimeTypes = FormatDetailValues(configuration.DetectedRuntimeTypes);
if (!string.IsNullOrWhiteSpace(detectedRuntimeTypes))
{
details.Add(new ProviderDetailDescriptor(
providerKind.GetLocalModelDetectedRuntimeTypeLabel(),
detectedRuntimeTypes));
}
var supportedRuntimeTypes = FormatSupportedModels(configuration.SupportedRuntimeTypes);
if (!string.IsNullOrWhiteSpace(supportedRuntimeTypes))
{
details.Add(new ProviderDetailDescriptor(
providerKind.GetLocalModelSupportedRuntimeTypesLabel(),
supportedRuntimeTypes));
}
if (!configuration.IsReady)
{
suggestedModelName = configuration.SuggestedModelName ?? string.Empty;
supportedModelNames = configuration.SupportedModelNames;
status = string.IsNullOrWhiteSpace(configuration.ModelPath)
? AgentProviderStatus.RequiresSetup
: AgentProviderStatus.Error;
statusSummary = string.IsNullOrWhiteSpace(configuration.ValidationErrorMessage)
? providerKind.GetLocalModelMissingSummary()
: configuration.ValidationErrorMessage;
canCreateAgents = false;
}
else
{
suggestedModelName = ResolveSuggestedModel(
defaultModelName,
configuration.SuggestedModelName,
configuration.SupportedModelNames);
supportedModelNames = configuration.SupportedModelNames;
details.AddRange(CreateProviderDetails(installedVersion, suggestedModelName, supportedModelNames));
statusSummary = providerKind.GetLocalModelReadySummary();
canCreateAgents = true;
}
}
else if (!isBuiltIn)
{
executablePath = ResolveExecutablePath(commandName);
if (string.IsNullOrWhiteSpace(executablePath))
{
details.Add(new ProviderDetailDescriptor("Install command", installCommand));
actions.Add(new ProviderActionDescriptor(InstallActionLabel, InstallActionSummary, installCommand, ProviderActionKind.CopyCommand));
status = AgentProviderStatus.RequiresSetup;
statusSummary = string.Format(System.Globalization.CultureInfo.InvariantCulture, MissingCliSummaryCompositeFormat, displayName);
canCreateAgents = false;
}
else
{
var metadata = await ResolveMetadataAsync(providerKind, executablePath, cancellationToken).ConfigureAwait(false);
installedVersion = metadata.InstalledVersion;
if (!LooksLikeInstalledVersion(installedVersion, commandName))
{
installedVersion = ReadVersion(executablePath, ["--version"]);
}
actions.Add(new ProviderActionDescriptor(OpenCliActionLabel, OpenCliActionSummary, $"{commandName} --version", ProviderActionKind.CopyCommand));
suggestedModelName = ResolveSuggestedModel(
defaultModelName,
metadata.SuggestedModelName,
metadata.SupportedModels);
supportedModelNames = ResolveSupportedModels(
defaultModelName,
suggestedModelName,
fallbackModels,
metadata.SupportedModels);
details.AddRange(CreateProviderDetails(installedVersion, suggestedModelName, supportedModelNames));
statusSummary = string.Format(System.Globalization.CultureInfo.InvariantCulture, ReadySummaryCompositeFormat, displayName);
canCreateAgents = true;
}
}
if (!preference.IsEnabled)
{
status = AgentProviderStatus.Disabled;
statusSummary = $"{DisabledStatusSummary} {statusSummary}";
canCreateAgents = false;
}
return new ProviderStatusProbeResult(
new ProviderStatusDescriptor(
providerId,
providerKind,
displayName,
commandName,
status,
statusSummary,
suggestedModelName,
supportedModelNames,
installedVersion,
preference.IsEnabled,
canCreateAgents,
details,
actions),
executablePath);
}
private static async Task<ProviderStatusProbeResult> ProbeProviderAsync(
AgentProviderKind providerKind,
ProviderPreferenceRecord preference,
IReadOnlyList<ProviderLocalModelRecord> localModels,
CancellationToken cancellationToken)
{
try
{
return await Task.Run(
async () => await BuildProviderStatusAsync(providerKind, preference, localModels, cancellationToken).ConfigureAwait(false),
CancellationToken.None)
.WaitAsync(ProviderProbeTimeout, cancellationToken)
.ConfigureAwait(false);
}
catch (OperationCanceledException) when (cancellationToken.IsCancellationRequested)
{
throw;
}
catch (TimeoutException)
{
return CreateTimedOutProviderStatus(providerKind, preference);
}
}
private static ProviderStatusProbeResult CreateTimedOutProviderStatus(
AgentProviderKind providerKind,
ProviderPreferenceRecord preference)
{
var commandName = providerKind.GetCommandName();
var displayName = providerKind.GetDisplayName();
var suggestedModelName = providerKind.GetDefaultModelName();
IReadOnlyList<string> supportedModelNames = string.IsNullOrWhiteSpace(suggestedModelName)
? Array.Empty<string>()
: [suggestedModelName];
var executablePath = ResolveExecutablePath(commandName);
var actions = new List<ProviderActionDescriptor>();
if (string.IsNullOrWhiteSpace(executablePath))
{
actions.Add(new ProviderActionDescriptor(
InstallActionLabel,
InstallActionSummary,
providerKind.GetInstallCommand(),
ProviderActionKind.CopyCommand));
}
else
{
actions.Add(new ProviderActionDescriptor(
OpenCliActionLabel,
TimedOutActionSummary,
$"{commandName} --version",
ProviderActionKind.CopyCommand));
}
var details = CreateProviderDetails(
installedVersion: null,
suggestedModelName,
supportedModelNames);
var status = AgentProviderStatus.Error;
var statusSummary = string.Format(
System.Globalization.CultureInfo.InvariantCulture,
TimedOutSummaryCompositeFormat,
displayName);
var canCreateAgents = false;
if (!preference.IsEnabled)
{
status = AgentProviderStatus.Disabled;
statusSummary = $"{DisabledStatusSummary} {statusSummary}";
}
return new ProviderStatusProbeResult(
new ProviderStatusDescriptor(
AgentSessionDeterministicIdentity.CreateProviderId(commandName),
providerKind,
displayName,
commandName,
status,
statusSummary,
suggestedModelName,
supportedModelNames,
null,
preference.IsEnabled,
canCreateAgents,
details,
actions),
executablePath);
}
private static async ValueTask<ProviderCliMetadataSnapshot> ResolveMetadataAsync(
AgentProviderKind providerKind,
string executablePath,
CancellationToken cancellationToken)
{
return providerKind switch
{
AgentProviderKind.Codex => CreateCodexSnapshot(CodexCliMetadataReader.TryRead(executablePath)),
AgentProviderKind.ClaudeCode => ClaudeCodeCliMetadataReader.TryRead(executablePath),
AgentProviderKind.GitHubCopilot => await CopilotCliMetadataReader.TryReadAsync(
executablePath,
cancellationToken).ConfigureAwait(false),
AgentProviderKind.Gemini => GeminiCliMetadataReader.TryRead(executablePath),
_ => new ProviderCliMetadataSnapshot(null, null, []),
};
}
private static ProviderCliMetadataSnapshot CreateCodexSnapshot(CodexCliMetadataSnapshot? metadata)
{
return new ProviderCliMetadataSnapshot(
metadata?.InstalledVersion,
metadata?.DefaultModel,
metadata?.AvailableModels ?? []);
}
private static string ResolveSuggestedModel(
string defaultModelName,
string? suggestedModelName,
IReadOnlyList<string> discoveredModels)
{
if (!string.IsNullOrWhiteSpace(suggestedModelName))
{
return suggestedModelName;
}
var discoveredModel = discoveredModels.FirstOrDefault(static model => !string.IsNullOrWhiteSpace(model));
return string.IsNullOrWhiteSpace(discoveredModel)
? defaultModelName
: discoveredModel;
}
private static bool LooksLikeInstalledVersion(string? installedVersion, string commandName)
{
if (string.IsNullOrWhiteSpace(installedVersion))
{
return false;
}
if (string.Equals(installedVersion, commandName, StringComparison.OrdinalIgnoreCase))
{
return false;
}
return installedVersion.Any(char.IsDigit);
}
private static IReadOnlyList<string> ResolveSupportedModels(
string defaultModelName,
string suggestedModelName,
IReadOnlyList<string> fallbackModels,
IReadOnlyList<string> discoveredModels)
{
return [.. EnumerateSupportedModels(defaultModelName, suggestedModelName, fallbackModels, discoveredModels)];
}
private static IEnumerable<string> EnumerateSupportedModels(
string defaultModelName,
string suggestedModelName,
IReadOnlyList<string> fallbackModels,
IReadOnlyList<string> discoveredModels)
{
HashSet<string> seen = new(StringComparer.OrdinalIgnoreCase);
foreach (var model in new[] { suggestedModelName, defaultModelName }
.Concat(discoveredModels)
.Concat(fallbackModels))
{
if (string.IsNullOrWhiteSpace(model) || !seen.Add(model))
{
continue;
}
yield return model;
}
}
private static List<ProviderDetailDescriptor> CreateProviderDetails(
string? installedVersion,
string suggestedModelName,
IReadOnlyList<string> supportedModelNames)
{
List<ProviderDetailDescriptor> details = [];
if (!string.IsNullOrWhiteSpace(installedVersion))
{
details.Add(new ProviderDetailDescriptor("Installed version", installedVersion));
}
if (!string.IsNullOrWhiteSpace(suggestedModelName))
{
details.Add(new ProviderDetailDescriptor("Suggested model", suggestedModelName));
}
var supportedModels = FormatSupportedModels(supportedModelNames);
if (!string.IsNullOrWhiteSpace(supportedModels))
{
details.Add(new ProviderDetailDescriptor("Supported models", supportedModels));
}
return details;
}
private static string FormatSupportedModels(IReadOnlyList<string> models)
{
if (models.Count == 0)
{
return string.Empty;
}
const int limit = 8;
var visibleModels = models
.Where(static model => !string.IsNullOrWhiteSpace(model))
.Distinct(StringComparer.Ordinal)
.Take(limit)
.ToArray();
if (visibleModels.Length == 0)
{
return string.Empty;
}
var remaining = models
.Where(static model => !string.IsNullOrWhiteSpace(model))
.Distinct(StringComparer.Ordinal)
.Count() - visibleModels.Length;
var summary = string.Join(", ", visibleModels);
return remaining > 0
? $"{summary} (+{remaining} more)"
: summary;
}
private static string FormatDetailValues(IReadOnlyList<string> values)
{
return string.Join(
Environment.NewLine,
values
.Where(static value => !string.IsNullOrWhiteSpace(value))
.Distinct(StringComparer.OrdinalIgnoreCase));
}
private static string? ResolveExecutablePath(string commandName)
{
if (OperatingSystem.IsBrowser())
{
return null;
}
var searchPaths = (Environment.GetEnvironmentVariable("PATH") ?? string.Empty)
.Split(Path.PathSeparator, StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);
foreach (var searchPath in searchPaths)
{
foreach (var candidate in EnumerateCandidates(searchPath, commandName))
{
if (File.Exists(candidate))
{
return candidate;
}
}
}
return null;
}
private static string ReadVersion(string executablePath, IReadOnlyList<string> arguments)
{
var output = ReadOutput(executablePath, arguments);
var firstLine = output
.Split(Environment.NewLine, StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries)
.FirstOrDefault();
if (string.IsNullOrWhiteSpace(firstLine))
{
return EmptyOutput;
}
var separatorIndex = firstLine.IndexOf(VersionSeparator, StringComparison.OrdinalIgnoreCase);
return separatorIndex >= 0
? firstLine[(separatorIndex + VersionSeparator.Length)..].Trim(' ', ':')
: firstLine.Trim();
}
private static string ReadOutput(string executablePath, IReadOnlyList<string> arguments)
{
var execution = Execute(executablePath, arguments);
if (!execution.Succeeded)
{
return EmptyOutput;
}
return string.IsNullOrWhiteSpace(execution.StandardOutput)
? execution.StandardError
: execution.StandardOutput;
}
private static ToolchainCommandExecution Execute(string executablePath, IReadOnlyList<string> arguments)
{
var startInfo = new ProcessStartInfo
{
FileName = executablePath,
RedirectStandardOutput = true,
RedirectStandardError = true,
UseShellExecute = false,
CreateNoWindow = true,
};
foreach (var argument in arguments)
{
startInfo.ArgumentList.Add(argument);
}
Process? process;
try
{
process = Process.Start(startInfo);
}
catch
{
return ToolchainCommandExecution.LaunchFailed;
}
if (process is null)
{
return ToolchainCommandExecution.LaunchFailed;
}
using (process)
{
var standardOutputTask = ObserveRedirectedStream(process.StandardOutput.ReadToEndAsync());
var standardErrorTask = ObserveRedirectedStream(process.StandardError.ReadToEndAsync());
if (!process.WaitForExit((int)CommandTimeout.TotalMilliseconds))
{
TryTerminate(process);
WaitForTermination(process);
return new ToolchainCommandExecution(
true,
false,
AwaitStreamRead(standardOutputTask),
AwaitStreamRead(standardErrorTask));
}
return new ToolchainCommandExecution(
true,
process.ExitCode == 0,
AwaitStreamRead(standardOutputTask),
AwaitStreamRead(standardErrorTask));
}
}
private static IEnumerable<string> EnumerateCandidates(string searchPath, string commandName)
{
yield return Path.Combine(searchPath, commandName);
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
yield break;
}
foreach (var extension in (Environment.GetEnvironmentVariable("PATHEXT") ?? ".EXE;.CMD;.BAT")
.Split(';', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries))
{
yield return Path.Combine(searchPath, string.Concat(commandName, extension));
}
}
private static Task<string> ObserveRedirectedStream(Task<string> readTask)
{
_ = readTask.ContinueWith(
static task => _ = task.Exception,
CancellationToken.None,
TaskContinuationOptions.OnlyOnFaulted | TaskContinuationOptions.ExecuteSynchronously,
TaskScheduler.Default);
return readTask;
}
private static string AwaitStreamRead(Task<string> readTask)
{
try
{
if (!readTask.Wait(RedirectDrainTimeout))
{
return EmptyOutput;
}
return readTask.GetAwaiter().GetResult();
}
catch
{
return EmptyOutput;
}
}
private static void TryTerminate(Process process)
{
try
{
if (!process.HasExited)
{
process.Kill(entireProcessTree: true);
}
}
catch
{
}
}
private static void WaitForTermination(Process process)
{
try
{
if (!process.HasExited)
{
process.WaitForExit((int)RedirectDrainTimeout.TotalMilliseconds);
}
}
catch
{
}
}
private readonly record struct ToolchainCommandExecution(bool Launched, bool Succeeded, string StandardOutput, string StandardError)
{
public static ToolchainCommandExecution LaunchFailed => new(false, false, EmptyOutput, EmptyOutput);
}
}