Skip to content

Build your personal knowledge base with Trilium Notes

fix(llm): resolve the Windows .cmd shim for the Copilot CLI

Elian Doran62c4f90ac6a1
diff --git a/apps/server/src/services/llm/providers/copilot_binary.spec.ts b/apps/server/src/services/llm/providers/copilot_binary.spec.ts
index d1c875c037..29759f02a0 100644
--- a/apps/server/src/services/llm/providers/copilot_binary.spec.ts
+++ b/apps/server/src/services/llm/providers/copilot_binary.spec.ts
@@ -118,6 +118,30 @@ describe("resolveCopilotBinaryPath", () => {
expect(execFileMock.mock.calls[0][2]).toMatchObject({ shell: true });
});
+ it("prefers the .cmd shim over the extensionless bash script npm installs beside it", async () => {
+ stubPlatform("win32");
+ // The real `npm install -g @github/copilot` layout: a POSIX `sh`
+ // script (for Git Bash) sits next to the Windows shims. Node cannot
+ // spawn the bash script — resolving it fails with a misleading
+ // "found it but it failed to run" ENOENT.
+ const dir = path.join("npm", "prefix");
+ const shim = path.join(dir, "copilot.cmd");
+ const bashScript = path.join(dir, "copilot");
+ process.env.PATH = dir;
+ existsSyncMock.mockImplementation((candidate: string) => candidate === shim || candidate === bashScript);
+ probeSucceeds();
+
+ await expect(resolveCopilotBinaryPath()).resolves.toBe(shim);
+
+ // With only the unusable bash script present, the bare name is
+ // skipped entirely so the user gets the actionable install message
+ // instead of an opaque spawn failure.
+ resetCopilotBinaryCache();
+ existsSyncMock.mockImplementation((candidate: string) => candidate === bashScript);
+
+ await expect(resolveCopilotBinaryPath()).rejects.toThrow(/GitHub Copilot CLI not found/);
+ });
+
it("rejects with install instructions when `copilot` is nowhere on PATH (or PATH is unset)", async () => {
stubPlatform("linux");
delete process.env.PATH;
diff --git a/apps/server/src/services/llm/providers/copilot_binary.ts b/apps/server/src/services/llm/providers/copilot_binary.ts
index f08254ad85..b51e2d1e79 100644
--- a/apps/server/src/services/llm/providers/copilot_binary.ts
+++ b/apps/server/src/services/llm/providers/copilot_binary.ts
@@ -92,8 +92,11 @@ export function needsShell(binary: string): boolean {
}
function findOnPath(binary: string): string | undefined {
- // Windows resolves executables via PATHEXT; on POSIX the bare name suffices.
- const extensions = process.platform === "win32" ? ["", ".cmd", ".exe", ".bat"] : [""];
+ // On Windows, npm-installed packages create a bare extensionless file (a
+ // POSIX bash script for Git Bash/WSL) alongside the real .cmd/.exe shims.
+ // The bash script can't be executed by Node's execFile/spawn, so we must
+ // try the Windows-native extensions first and skip the bare name entirely.
+ const extensions = process.platform === "win32" ? [".cmd", ".exe", ".bat"] : [""];
for (const dir of (process.env.PATH ?? "").split(path.delimiter)) {
if (!dir) {
continue;