From 2ff58c5e24ff24fbac7ebc5214d5921013511830 Mon Sep 17 00:00:00 2001 From: Sergio Padrino Date: Wed, 11 Mar 2026 13:47:30 +0100 Subject: [PATCH 1/3] Don't pass cliPath to client if cliUrl was provided --- nodejs/src/client.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nodejs/src/client.ts b/nodejs/src/client.ts index bd4cc1960..6c0c08aee 100644 --- a/nodejs/src/client.ts +++ b/nodejs/src/client.ts @@ -230,7 +230,7 @@ export class CopilotClient { this.onListModels = options.onListModels; this.options = { - cliPath: options.cliPath || getBundledCliPath(), + cliPath: options.cliUrl ? undefined : (options.cliPath || getBundledCliPath()), cliArgs: options.cliArgs ?? [], cwd: options.cwd ?? process.cwd(), port: options.port || 0, From b1503f6a58b38ddd23c8b3c9792fb44753d1845a Mon Sep 17 00:00:00 2001 From: Sergio Padrino Date: Wed, 11 Mar 2026 14:12:14 +0100 Subject: [PATCH 2/3] Add cliPath option and validate it at runtime Include an optional cliPath in the client options type and update the Omit<> to account for it. Simplify the default assignment for cliPath (use cliUrl to disable, otherwise use provided cliPath or bundled fallback). Add a runtime check that throws a clear error if cliPath is not available before trying to access the file system, ensuring users provide a local CLI path or use cliUrl. --- nodejs/src/client.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/nodejs/src/client.ts b/nodejs/src/client.ts index 6c0c08aee..954d88b59 100644 --- a/nodejs/src/client.ts +++ b/nodejs/src/client.ts @@ -141,8 +141,12 @@ export class CopilotClient { private sessions: Map = new Map(); private stderrBuffer: string = ""; // Captures CLI stderr for error messages private options: Required< - Omit + Omit< + CopilotClientOptions, + "cliPath" | "cliUrl" | "githubToken" | "useLoggedInUser" | "onListModels" + > > & { + cliPath?: string; cliUrl?: string; githubToken?: string; useLoggedInUser?: boolean; @@ -230,7 +234,7 @@ export class CopilotClient { this.onListModels = options.onListModels; this.options = { - cliPath: options.cliUrl ? undefined : (options.cliPath || getBundledCliPath()), + cliPath: options.cliUrl ? undefined : options.cliPath || getBundledCliPath(), cliArgs: options.cliArgs ?? [], cwd: options.cwd ?? process.cwd(), port: options.port || 0, @@ -1135,6 +1139,12 @@ export class CopilotClient { envWithoutNodeDebug.COPILOT_SDK_AUTH_TOKEN = this.options.githubToken; } + if (!this.options.cliPath) { + throw new Error( + "Path to Copilot CLI is required. Please provide it via the cliPath option, or use cliUrl to rely on a remote CLI." + ); + } + // Verify CLI exists before attempting to spawn if (!existsSync(this.options.cliPath)) { throw new Error( From 1a4ffed721bf53e7a0505b2098670341468fe2d0 Mon Sep 17 00:00:00 2001 From: Sergio Padrino Date: Wed, 11 Mar 2026 14:16:36 +0100 Subject: [PATCH 3/3] Add test: cliPath undefined when cliUrl set Add a unit test to nodejs/test/client.test.ts that verifies CopilotClient does not resolve or set options.cliPath when instantiated with a cliUrl. This ensures providing a remote CLI URL doesn't trigger resolution of a local CLI path. --- nodejs/test/client.test.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/nodejs/test/client.test.ts b/nodejs/test/client.test.ts index ef227b698..7206c903b 100644 --- a/nodejs/test/client.test.ts +++ b/nodejs/test/client.test.ts @@ -210,6 +210,15 @@ describe("CopilotClient", () => { expect((client as any).isExternalServer).toBe(true); }); + + it("should not resolve cliPath when cliUrl is provided", () => { + const client = new CopilotClient({ + cliUrl: "localhost:8080", + logLevel: "error", + }); + + expect(client["options"].cliPath).toBeUndefined(); + }); }); describe("Auth options", () => {