diff --git a/apps/server/src/orchestration-v2/Adapters/AcpRegistryAdapterV2.test.ts b/apps/server/src/orchestration-v2/Adapters/AcpRegistryAdapterV2.test.ts index 35c0ec29d1148..4e36f74e3c510 100644 --- a/apps/server/src/orchestration-v2/Adapters/AcpRegistryAdapterV2.test.ts +++ b/apps/server/src/orchestration-v2/Adapters/AcpRegistryAdapterV2.test.ts @@ -1472,6 +1472,13 @@ describe("AcpRegistryAdapterV2", () => { yield* steering({ source: "local", commandPath: "C:\\tools\\copilot.cmd" }), copilot, ); + assert.deepEqual( + yield* steering({ + source: "local", + commandPath: "C:\\tools\\github-copilot-cli.exe", + }), + copilot, + ); assert.deepEqual(yield* steering({ agentId: "gemini" }), { ...copilot, supportsSteeringByInterruptRestart: true, diff --git a/packages/provider-acp-registry/src/server/adapter.localCommands.test.ts b/packages/provider-acp-registry/src/server/adapter.localCommands.test.ts new file mode 100644 index 0000000000000..7686d5766904c --- /dev/null +++ b/packages/provider-acp-registry/src/server/adapter.localCommands.test.ts @@ -0,0 +1,41 @@ +import { describe, expect, it } from "vite-plus/test"; + +import { matchesLocalAgentCommand } from "./adapter.ts"; + +const KIMI = /^kimi(?:-code)?(\.exe|\.cmd)?$/i; +const COPILOT = /^(?:copilot|github-copilot-cli)(\.exe|\.cmd)?$/i; +const CLAUDE = /^claude-agent-acp(\.exe|\.cmd)?$/i; + +describe("matchesLocalAgentCommand", () => { + it.each([ + ["kimi-code", true], + ["kimi", true], + ["kimi-code.exe", true], + ["kimi.cmd", true], + ["kimicode", false], + ])("local command %s enables Kimi handling: %s", (command, expected) => { + expect(matchesLocalAgentCommand(`/usr/local/bin/${command}`, "local", KIMI)).toBe(expected); + }); + + it.each([ + ["copilot", true], + ["github-copilot-cli.exe", true], + ["copilot-cli.CMD", false], + ["copilotx", false], + ])("local command %s enables Copilot handling: %s", (command, expected) => { + expect(matchesLocalAgentCommand(`C:\\Tools\\${command}`, "local", COPILOT)).toBe(expected); + }); + + it.each([ + ["claude-acp", false], + ["claude-agent-acp.exe", true], + ["claude", false], + ])("local command %s enables Claude handling: %s", (command, expected) => { + expect(matchesLocalAgentCommand(`/opt/bin/${command}`, "local", CLAUDE)).toBe(expected); + }); + + it("never matches non-local sources", () => { + expect(matchesLocalAgentCommand("/usr/bin/kimi-code", "registry", KIMI)).toBe(false); + expect(matchesLocalAgentCommand("/usr/bin/kimi-code", "npx", KIMI)).toBe(false); + }); +}); diff --git a/packages/provider-acp-registry/src/server/adapter.ts b/packages/provider-acp-registry/src/server/adapter.ts index ce5a2b94531c4..45f2fcccb4111 100644 --- a/packages/provider-acp-registry/src/server/adapter.ts +++ b/packages/provider-acp-registry/src/server/adapter.ts @@ -186,6 +186,15 @@ const isHermes = ( initializeResult: AcpSessionRuntime.AcpSessionRuntimeStartResult["initializeResult"], ) => initializeResult.agentInfo?.name === "hermes-agent"; +/** A local install launches the binary directly with no registry id, so detect it by basename. */ +export function matchesLocalAgentCommand( + commandPath: string, + source: string, + pattern: RegExp, +): boolean { + return source === "local" && pattern.test(commandPath.split(/[\\/]/).pop() ?? ""); +} + export const makeAcpRegistryAdapterV2 = Effect.fn("makeAcpRegistryAdapterV2")(function* ( options: AcpRegistryAdapterV2Options, ) { @@ -210,21 +219,29 @@ export const makeAcpRegistryAdapterV2 = Effect.fn("makeAcpRegistryAdapterV2")(fu /^opencode(?:-v2)?(\.exe|\.cmd)?$/i.test( options.settings.commandPath.split(/[\\/]/).pop() ?? "", )); - // Local installs launch the `copilot` binary directly with no registry id. + // Local installs launch the binary directly with no registry id, named either + // for the CLI or for its registry id. const isCopilot = registryAgentId === "github-copilot-cli" || - (options.settings.source === "local" && - /^copilot(\.exe|\.cmd)?$/i.test(options.settings.commandPath.split(/[\\/]/).pop() ?? "")); + matchesLocalAgentCommand( + options.settings.commandPath, + options.settings.source, + /^(?:copilot|github-copilot-cli)(\.exe|\.cmd)?$/i, + ); const isKimi = registryAgentId === "kimi-code" || - (options.settings.source === "local" && - /^kimi(\.exe|\.cmd)?$/i.test(options.settings.commandPath.split(/[\\/]/).pop() ?? "")); + matchesLocalAgentCommand( + options.settings.commandPath, + options.settings.source, + /^kimi(?:-code)?(\.exe|\.cmd)?$/i, + ); const isClaude = registryAgentId === "claude-acp" || - (options.settings.source === "local" && - /^claude-agent-acp(\.exe|\.cmd)?$/i.test( - options.settings.commandPath.split(/[\\/]/).pop() ?? "", - )); + matchesLocalAgentCommand( + options.settings.commandPath, + options.settings.source, + /^claude-agent-acp(\.exe|\.cmd)?$/i, + ); const runtimeOptions = isClaude ? { ...options,