mirror of
https://github.com/davidkaya/aryx.git
synced 2026-08-05 03:18:44 +02:00
fix: always use system copilot cli
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="GitHub.Copilot.SDK" Version="0.2.0" />
|
||||
<PackageReference Include="Microsoft.Agents.AI" Version="1.0.0-rc4" />
|
||||
<PackageReference Include="Microsoft.Agents.AI.GitHub.Copilot" Version="1.0.0-preview.260311.1" />
|
||||
<PackageReference Include="Microsoft.Agents.AI.Workflows" Version="1.0.0-rc4" />
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
using System.Runtime.InteropServices;
|
||||
using GitHub.Copilot.SDK;
|
||||
|
||||
namespace Kopaya.AgentHost.Services;
|
||||
@@ -8,62 +7,34 @@ internal static class CopilotCliPathResolver
|
||||
private const string CopilotCommandName = "copilot";
|
||||
private const string DefaultWindowsPathExtensions = ".COM;.EXE;.BAT;.CMD";
|
||||
|
||||
public static CopilotClientOptions? CreateClientOptions()
|
||||
public static CopilotClientOptions CreateClientOptions()
|
||||
{
|
||||
CopilotCliResolution resolution = Resolve(
|
||||
Environment.ProcessPath,
|
||||
string? cliPath = Resolve(
|
||||
Environment.GetEnvironmentVariable("PATH"),
|
||||
Environment.GetEnvironmentVariable("PATHEXT"),
|
||||
RuntimeInformation.IsOSPlatform(OSPlatform.Windows),
|
||||
OperatingSystem.IsWindows(),
|
||||
File.Exists);
|
||||
|
||||
if (!resolution.ShouldOverrideCliPath)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(resolution.CliPath))
|
||||
if (string.IsNullOrWhiteSpace(cliPath))
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
"Development sidecar could not find the system-installed 'copilot' command on PATH. Install the GitHub Copilot CLI or provide an explicit CliPath.");
|
||||
"Kopaya requires the system-installed 'copilot' command on PATH. Install the GitHub Copilot CLI and ensure it is available in the current environment.");
|
||||
}
|
||||
|
||||
return new CopilotClientOptions
|
||||
{
|
||||
CliPath = resolution.CliPath,
|
||||
CliPath = cliPath,
|
||||
};
|
||||
}
|
||||
|
||||
internal static CopilotCliResolution Resolve(
|
||||
string? processPath,
|
||||
internal static string? Resolve(
|
||||
string? pathValue,
|
||||
string? pathExtValue,
|
||||
bool isWindows,
|
||||
Func<string, bool> fileExists)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(fileExists);
|
||||
|
||||
if (!IsDevelopmentHost(processPath))
|
||||
{
|
||||
return default;
|
||||
}
|
||||
|
||||
return new CopilotCliResolution(
|
||||
ShouldOverrideCliPath: true,
|
||||
CliPath: ResolveCliPath(pathValue, pathExtValue, isWindows, fileExists));
|
||||
}
|
||||
|
||||
private static bool IsDevelopmentHost(string? processPath)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(processPath))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return string.Equals(
|
||||
Path.GetFileNameWithoutExtension(processPath),
|
||||
"dotnet",
|
||||
StringComparison.OrdinalIgnoreCase);
|
||||
return ResolveCliPath(pathValue, pathExtValue, isWindows, fileExists);
|
||||
}
|
||||
|
||||
private static string? ResolveCliPath(
|
||||
@@ -128,5 +99,3 @@ internal static class CopilotCliPathResolver
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal readonly record struct CopilotCliResolution(bool ShouldOverrideCliPath, string? CliPath);
|
||||
|
||||
@@ -170,11 +170,11 @@ public sealed class CopilotWorkflowRunner
|
||||
{
|
||||
List<IAsyncDisposable> disposables = [];
|
||||
List<AIAgent> agents = [];
|
||||
CopilotClientOptions? clientOptions = CopilotCliPathResolver.CreateClientOptions();
|
||||
CopilotClientOptions clientOptions = CopilotCliPathResolver.CreateClientOptions();
|
||||
|
||||
foreach (PatternAgentDefinitionDto definition in pattern.Agents)
|
||||
{
|
||||
CopilotClient client = clientOptions is null ? new() : new(clientOptions);
|
||||
CopilotClient client = new(clientOptions);
|
||||
await client.StartAsync(cancellationToken).ConfigureAwait(false);
|
||||
|
||||
SessionConfig sessionConfig = new()
|
||||
@@ -263,7 +263,7 @@ public sealed class CopilotWorkflowRunner
|
||||
{
|
||||
return Task.FromResult(new PermissionRequestResult
|
||||
{
|
||||
Kind = "approved",
|
||||
Kind = PermissionRequestResultKind.Approved,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ namespace Kopaya.AgentHost.Tests;
|
||||
public sealed class CopilotCliPathResolverTests
|
||||
{
|
||||
[Fact]
|
||||
public void Resolve_UsesCopilotFromPathDuringDevelopment()
|
||||
public void Resolve_UsesCopilotFromPath()
|
||||
{
|
||||
string copilotDirectory = @"C:\tools\copilot";
|
||||
HashSet<string> existingFiles = new(StringComparer.OrdinalIgnoreCase)
|
||||
@@ -13,42 +13,42 @@ public sealed class CopilotCliPathResolverTests
|
||||
Path.Combine(copilotDirectory, "copilot.exe"),
|
||||
};
|
||||
|
||||
CopilotCliResolution resolution = CopilotCliPathResolver.Resolve(
|
||||
processPath: @"C:\Program Files\dotnet\dotnet.exe",
|
||||
string? cliPath = CopilotCliPathResolver.Resolve(
|
||||
pathValue: $"C:\\other;\"{copilotDirectory}\"",
|
||||
pathExtValue: ".COM;.EXE;.BAT;.CMD",
|
||||
isWindows: true,
|
||||
fileExists: existingFiles.Contains);
|
||||
|
||||
Assert.True(resolution.ShouldOverrideCliPath);
|
||||
Assert.Equal(Path.Combine(copilotDirectory, "copilot.exe"), resolution.CliPath, ignoreCase: true);
|
||||
Assert.Equal(Path.Combine(copilotDirectory, "copilot.exe"), cliPath, ignoreCase: true);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Resolve_LeavesPackagedRuntimeOnBundledCli()
|
||||
public void Resolve_UsesDefaultWindowsExtensionsWhenPathExtMissing()
|
||||
{
|
||||
CopilotCliResolution resolution = CopilotCliPathResolver.Resolve(
|
||||
processPath: @"C:\Program Files\Kopaya\Kopaya.AgentHost.exe",
|
||||
pathValue: @"C:\tools",
|
||||
pathExtValue: ".COM;.EXE;.BAT;.CMD",
|
||||
string copilotDirectory = @"C:\tools\copilot";
|
||||
HashSet<string> existingFiles = new(StringComparer.OrdinalIgnoreCase)
|
||||
{
|
||||
Path.Combine(copilotDirectory, "copilot.cmd"),
|
||||
};
|
||||
|
||||
string? cliPath = CopilotCliPathResolver.Resolve(
|
||||
pathValue: $"C:\\other;\"{copilotDirectory}\"",
|
||||
pathExtValue: null,
|
||||
isWindows: true,
|
||||
fileExists: _ => true);
|
||||
fileExists: existingFiles.Contains);
|
||||
|
||||
Assert.False(resolution.ShouldOverrideCliPath);
|
||||
Assert.Null(resolution.CliPath);
|
||||
Assert.Equal(Path.Combine(copilotDirectory, "copilot.cmd"), cliPath, ignoreCase: true);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Resolve_ReportsMissingCopilotWhenDevelopmentPathDoesNotContainIt()
|
||||
public void Resolve_ReturnsNullWhenPathDoesNotContainCopilot()
|
||||
{
|
||||
CopilotCliResolution resolution = CopilotCliPathResolver.Resolve(
|
||||
processPath: @"C:\Program Files\dotnet\dotnet.exe",
|
||||
string? cliPath = CopilotCliPathResolver.Resolve(
|
||||
pathValue: @"C:\tools;C:\other",
|
||||
pathExtValue: ".COM;.EXE;.BAT;.CMD",
|
||||
isWindows: true,
|
||||
fileExists: _ => false);
|
||||
|
||||
Assert.True(resolution.ShouldOverrideCliPath);
|
||||
Assert.Null(resolution.CliPath);
|
||||
Assert.Null(cliPath);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user