@theia/ai-copilot 1.75.0 → 1.76.0-next.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (150) hide show
  1. package/README.md +86 -14
  2. package/lib/browser/copilot-auth-dialog.d.ts.map +1 -1
  3. package/lib/browser/copilot-auth-dialog.js +12 -4
  4. package/lib/browser/copilot-auth-dialog.js.map +1 -1
  5. package/lib/browser/copilot-frontend-application-contribution.d.ts +15 -1
  6. package/lib/browser/copilot-frontend-application-contribution.d.ts.map +1 -1
  7. package/lib/browser/copilot-frontend-application-contribution.js +52 -24
  8. package/lib/browser/copilot-frontend-application-contribution.js.map +1 -1
  9. package/lib/common/copilot-auth-service.d.ts +27 -24
  10. package/lib/common/copilot-auth-service.d.ts.map +1 -1
  11. package/lib/common/copilot-language-models-manager.d.ts +3 -21
  12. package/lib/common/copilot-language-models-manager.d.ts.map +1 -1
  13. package/lib/common/copilot-language-models-manager.js +1 -13
  14. package/lib/common/copilot-language-models-manager.js.map +1 -1
  15. package/lib/common/copilot-preferences.d.ts +1 -0
  16. package/lib/common/copilot-preferences.d.ts.map +1 -1
  17. package/lib/common/copilot-preferences.js +24 -6
  18. package/lib/common/copilot-preferences.js.map +1 -1
  19. package/lib/common/index.d.ts +0 -1
  20. package/lib/common/index.d.ts.map +1 -1
  21. package/lib/common/index.js +0 -1
  22. package/lib/common/index.js.map +1 -1
  23. package/lib/node/copilot-auth-service-impl.d.ts +25 -16
  24. package/lib/node/copilot-auth-service-impl.d.ts.map +1 -1
  25. package/lib/node/copilot-auth-service-impl.js +67 -183
  26. package/lib/node/copilot-auth-service-impl.js.map +1 -1
  27. package/lib/node/copilot-auth-service-impl.spec.js +104 -168
  28. package/lib/node/copilot-auth-service-impl.spec.js.map +1 -1
  29. package/lib/node/copilot-backend-module.d.ts.map +1 -1
  30. package/lib/node/copilot-backend-module.js +10 -2
  31. package/lib/node/copilot-backend-module.js.map +1 -1
  32. package/lib/node/copilot-cli-auth-provider.d.ts +146 -0
  33. package/lib/node/copilot-cli-auth-provider.d.ts.map +1 -0
  34. package/lib/node/copilot-cli-auth-provider.js +430 -0
  35. package/lib/node/copilot-cli-auth-provider.js.map +1 -0
  36. package/lib/node/copilot-cli-auth-provider.spec.d.ts +2 -0
  37. package/lib/node/copilot-cli-auth-provider.spec.d.ts.map +1 -0
  38. package/lib/node/copilot-cli-auth-provider.spec.js +249 -0
  39. package/lib/node/copilot-cli-auth-provider.spec.js.map +1 -0
  40. package/lib/node/copilot-cli-locator.d.ts +120 -0
  41. package/lib/node/copilot-cli-locator.d.ts.map +1 -0
  42. package/lib/node/copilot-cli-locator.js +348 -0
  43. package/lib/node/copilot-cli-locator.js.map +1 -0
  44. package/lib/node/copilot-cli-locator.spec.d.ts +2 -0
  45. package/lib/node/copilot-cli-locator.spec.d.ts.map +1 -0
  46. package/lib/node/copilot-cli-locator.spec.js +327 -0
  47. package/lib/node/copilot-cli-locator.spec.js.map +1 -0
  48. package/lib/node/copilot-credential-store.d.ts +45 -0
  49. package/lib/node/copilot-credential-store.d.ts.map +1 -0
  50. package/lib/node/copilot-credential-store.js +96 -0
  51. package/lib/node/copilot-credential-store.js.map +1 -0
  52. package/lib/node/copilot-credential-store.spec.d.ts +2 -0
  53. package/lib/node/copilot-credential-store.spec.d.ts.map +1 -0
  54. package/lib/node/copilot-credential-store.spec.js +93 -0
  55. package/lib/node/copilot-credential-store.spec.js.map +1 -0
  56. package/lib/node/copilot-language-models-manager-impl.d.ts +20 -18
  57. package/lib/node/copilot-language-models-manager-impl.d.ts.map +1 -1
  58. package/lib/node/copilot-language-models-manager-impl.js +39 -67
  59. package/lib/node/copilot-language-models-manager-impl.js.map +1 -1
  60. package/lib/node/copilot-language-models-manager-impl.spec.d.ts +2 -0
  61. package/lib/node/copilot-language-models-manager-impl.spec.d.ts.map +1 -0
  62. package/lib/node/copilot-language-models-manager-impl.spec.js +119 -0
  63. package/lib/node/copilot-language-models-manager-impl.spec.js.map +1 -0
  64. package/lib/node/copilot-runtime-env.d.ts +20 -0
  65. package/lib/node/copilot-runtime-env.d.ts.map +1 -0
  66. package/lib/node/copilot-runtime-env.js +49 -0
  67. package/lib/node/copilot-runtime-env.js.map +1 -0
  68. package/lib/node/copilot-sdk-client-provider.d.ts +103 -0
  69. package/lib/node/copilot-sdk-client-provider.d.ts.map +1 -0
  70. package/lib/node/copilot-sdk-client-provider.js +247 -0
  71. package/lib/node/copilot-sdk-client-provider.js.map +1 -0
  72. package/lib/node/copilot-sdk-client-provider.spec.d.ts +2 -0
  73. package/lib/node/copilot-sdk-client-provider.spec.d.ts.map +1 -0
  74. package/lib/node/copilot-sdk-client-provider.spec.js +215 -0
  75. package/lib/node/copilot-sdk-client-provider.spec.js.map +1 -0
  76. package/lib/node/copilot-sdk-language-model.d.ts +85 -0
  77. package/lib/node/copilot-sdk-language-model.d.ts.map +1 -0
  78. package/lib/node/copilot-sdk-language-model.js +301 -0
  79. package/lib/node/copilot-sdk-language-model.js.map +1 -0
  80. package/lib/node/copilot-sdk-language-model.spec.d.ts +2 -0
  81. package/lib/node/copilot-sdk-language-model.spec.d.ts.map +1 -0
  82. package/lib/node/copilot-sdk-language-model.spec.js +302 -0
  83. package/lib/node/copilot-sdk-language-model.spec.js.map +1 -0
  84. package/lib/node/copilot-sdk-loader.d.ts +57 -0
  85. package/lib/node/copilot-sdk-loader.d.ts.map +1 -0
  86. package/lib/node/copilot-sdk-loader.js +133 -0
  87. package/lib/node/copilot-sdk-loader.js.map +1 -0
  88. package/lib/node/copilot-sdk-loader.spec.d.ts +2 -0
  89. package/lib/node/copilot-sdk-loader.spec.d.ts.map +1 -0
  90. package/lib/node/copilot-sdk-loader.spec.js +113 -0
  91. package/lib/node/copilot-sdk-loader.spec.js.map +1 -0
  92. package/lib/node/copilot-sdk-mappers.d.ts +49 -0
  93. package/lib/node/copilot-sdk-mappers.d.ts.map +1 -0
  94. package/lib/node/copilot-sdk-mappers.js +147 -0
  95. package/lib/node/copilot-sdk-mappers.js.map +1 -0
  96. package/lib/node/copilot-sdk-mappers.spec.d.ts +2 -0
  97. package/lib/node/copilot-sdk-mappers.spec.d.ts.map +1 -0
  98. package/lib/node/copilot-sdk-mappers.spec.js +133 -0
  99. package/lib/node/copilot-sdk-mappers.spec.js.map +1 -0
  100. package/lib/node/copilot-sdk-types.d.ts +198 -0
  101. package/lib/node/copilot-sdk-types.d.ts.map +1 -0
  102. package/lib/{common/copilot-oauth-config.js → node/copilot-sdk-types.js} +2 -13
  103. package/lib/node/copilot-sdk-types.js.map +1 -0
  104. package/lib/node/index.d.ts +9 -1
  105. package/lib/node/index.d.ts.map +1 -1
  106. package/lib/node/index.js +9 -1
  107. package/lib/node/index.js.map +1 -1
  108. package/package.json +4 -6
  109. package/src/browser/copilot-auth-dialog.tsx +12 -8
  110. package/src/browser/copilot-frontend-application-contribution.ts +62 -29
  111. package/src/common/copilot-auth-service.ts +28 -24
  112. package/src/common/copilot-language-models-manager.ts +3 -28
  113. package/src/common/copilot-preferences.ts +24 -5
  114. package/src/common/index.ts +0 -1
  115. package/src/node/copilot-auth-service-impl.spec.ts +122 -207
  116. package/src/node/copilot-auth-service-impl.ts +63 -218
  117. package/src/node/copilot-backend-module.ts +11 -2
  118. package/src/node/copilot-cli-auth-provider.spec.ts +315 -0
  119. package/src/node/copilot-cli-auth-provider.ts +444 -0
  120. package/src/node/copilot-cli-locator.spec.ts +386 -0
  121. package/src/node/copilot-cli-locator.ts +363 -0
  122. package/src/node/copilot-credential-store.spec.ts +106 -0
  123. package/src/node/copilot-credential-store.ts +99 -0
  124. package/src/node/copilot-language-models-manager-impl.spec.ts +137 -0
  125. package/src/node/copilot-language-models-manager-impl.ts +51 -85
  126. package/src/node/copilot-runtime-env.ts +46 -0
  127. package/src/node/copilot-sdk-client-provider.spec.ts +253 -0
  128. package/src/node/copilot-sdk-client-provider.ts +241 -0
  129. package/src/node/copilot-sdk-language-model.spec.ts +363 -0
  130. package/src/node/copilot-sdk-language-model.ts +329 -0
  131. package/src/node/copilot-sdk-loader.spec.ts +126 -0
  132. package/src/node/copilot-sdk-loader.ts +142 -0
  133. package/src/node/copilot-sdk-mappers.spec.ts +151 -0
  134. package/src/node/copilot-sdk-mappers.ts +161 -0
  135. package/src/node/copilot-sdk-types.ts +276 -0
  136. package/src/node/index.ts +9 -1
  137. package/lib/common/copilot-oauth-config.d.ts +0 -33
  138. package/lib/common/copilot-oauth-config.d.ts.map +0 -1
  139. package/lib/common/copilot-oauth-config.js.map +0 -1
  140. package/lib/node/copilot-language-model.d.ts +0 -34
  141. package/lib/node/copilot-language-model.d.ts.map +0 -1
  142. package/lib/node/copilot-language-model.js +0 -236
  143. package/lib/node/copilot-language-model.js.map +0 -1
  144. package/lib/node/copilot-language-model.spec.d.ts +0 -2
  145. package/lib/node/copilot-language-model.spec.d.ts.map +0 -1
  146. package/lib/node/copilot-language-model.spec.js +0 -89
  147. package/lib/node/copilot-language-model.spec.js.map +0 -1
  148. package/src/common/copilot-oauth-config.ts +0 -55
  149. package/src/node/copilot-language-model.spec.ts +0 -106
  150. package/src/node/copilot-language-model.ts +0 -273
@@ -0,0 +1,348 @@
1
+ "use strict";
2
+ // *****************************************************************************
3
+ // Copyright (C) 2026 EclipseSource GmbH and others.
4
+ //
5
+ // This program and the accompanying materials are made available under the
6
+ // terms of the Eclipse Public License v. 2.0 which is available at
7
+ // http://www.eclipse.org/legal/epl-2.0.
8
+ //
9
+ // This Source Code may also be made available under the following Secondary
10
+ // Licenses when the conditions for such availability set forth in the Eclipse
11
+ // Public License v. 2.0 are satisfied: GNU General Public License, version 2
12
+ // with the GNU Classpath Exception which is available at
13
+ // https://www.gnu.org/software/classpath/license.html.
14
+ //
15
+ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
16
+ // *****************************************************************************
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.CopilotCliLocator = exports.COPILOT_CLI_PATH_ENV = void 0;
19
+ const tslib_1 = require("tslib");
20
+ const child_process_1 = require("child_process");
21
+ const fs_1 = require("fs");
22
+ const module_1 = require("module");
23
+ const path_1 = require("path");
24
+ const util_1 = require("util");
25
+ const inversify_1 = require("@theia/core/shared/inversify");
26
+ const core_1 = require("@theia/core");
27
+ const execFileAsync = (0, util_1.promisify)(child_process_1.execFile);
28
+ /**
29
+ * Environment variable that points at the Copilot CLI, honored by the Copilot SDK as well.
30
+ */
31
+ exports.COPILOT_CLI_PATH_ENV = 'COPILOT_CLI_PATH';
32
+ /**
33
+ * Time after which looking up the global npm installation directory is given up on.
34
+ */
35
+ const NPM_ROOT_TIMEOUT_MS = 5_000;
36
+ /**
37
+ * Locates the executable of the GitHub Copilot CLI on the machine running the backend.
38
+ *
39
+ * The CLI is a native executable that GitHub ships in a platform-specific package. It is looked up
40
+ * rather than bundled, because it is a large proprietary binary that an application does not
41
+ * necessarily carry: a packaged application (for example an AppImage) cannot execute a binary from
42
+ * inside its archive, and an installation may deliberately not ship it at all. Users install the CLI
43
+ * themselves, the same way as for the Claude Code integration.
44
+ *
45
+ * The native executable is resolved rather than the `index.js` entry point of the same package, so
46
+ * that it can be spawned directly. Spawning the JavaScript entry point would require a Node.js
47
+ * executable, which the backend does not have at hand: `process.execPath` is the Electron binary in
48
+ * an Electron application, and starting that would start a second application instead of the CLI.
49
+ */
50
+ let CopilotCliLocator = class CopilotCliLocator {
51
+ /**
52
+ * Sets the location the user configured, which takes precedence over every other source.
53
+ * A changed value discards what was resolved before.
54
+ */
55
+ setConfiguredPath(path) {
56
+ const configured = path?.trim() || undefined;
57
+ if (configured !== this.configuredPath) {
58
+ this.configuredPath = configured;
59
+ this.resolution = undefined;
60
+ }
61
+ }
62
+ /**
63
+ * Resolves the executable of the Copilot CLI, and remembers it for later calls.
64
+ * Rejects with an explanation of where it was searched when there is none.
65
+ */
66
+ async resolve() {
67
+ if (!this.resolution) {
68
+ const resolution = this.doResolve();
69
+ this.resolution = resolution;
70
+ // Don't remember a failed lookup: the CLI can be installed while the backend is running.
71
+ // Only this lookup is forgotten, a later one may already be running.
72
+ resolution.catch(() => {
73
+ if (this.resolution === resolution) {
74
+ this.resolution = undefined;
75
+ }
76
+ });
77
+ }
78
+ return this.resolution;
79
+ }
80
+ async doResolve() {
81
+ if (this.configuredPath) {
82
+ const configured = await this.resolveConfiguredPath(this.configuredPath);
83
+ if (!configured) {
84
+ throw new Error(core_1.nls.localize('theia/ai/copilot/cliNotFoundAt', 'The configured GitHub Copilot CLI does not exist or is not executable: {0}', this.configuredPath));
85
+ }
86
+ return configured;
87
+ }
88
+ const attempted = [];
89
+ for (const source of [
90
+ () => this.environmentCandidates(),
91
+ () => this.bundledCandidates(),
92
+ () => this.pathCandidates(),
93
+ () => this.globalInstallCandidates()
94
+ ]) {
95
+ let candidates;
96
+ try {
97
+ candidates = await source();
98
+ }
99
+ catch (error) {
100
+ this.logger.warn('Copilot: failed to look for the Copilot CLI:', error);
101
+ continue;
102
+ }
103
+ for (const candidate of candidates) {
104
+ if (await this.isExecutable(candidate)) {
105
+ this.logger.info(`Copilot: using the Copilot CLI at ${candidate}.`);
106
+ return candidate;
107
+ }
108
+ attempted.push(candidate);
109
+ }
110
+ }
111
+ this.logger.warn(`Copilot: no Copilot CLI found, searched:\n${attempted.join('\n')}`);
112
+ throw new Error(core_1.nls.localize('theia/ai/copilot/cliNotFound', 'Could not find the GitHub Copilot CLI on the machine running the backend. Install it with '
113
+ + '`npm install -g @github/copilot`, or set the `ai-features.copilot.executablePath` preference to the location of '
114
+ + 'its executable. {0} locations were searched, see the backend log for the full list.', attempted.length));
115
+ }
116
+ /**
117
+ * Accepts the configured location either as the executable itself or as the directory holding it,
118
+ * so that both what a user has on their `PATH` and what a package manager installed can be given.
119
+ *
120
+ * A configured launcher is followed to the executable it would start, because that is what `which`
121
+ * or `whereis` report for a global installation. Starting the launcher would work as well, but only
122
+ * for as long as a Node.js is on the `PATH` of the backend, which is nothing to rely on.
123
+ */
124
+ async resolveConfiguredPath(configured) {
125
+ const candidates = [configured, ...this.getCliFileNames().map(name => (0, path_1.join)(configured, name))];
126
+ for (const candidate of candidates) {
127
+ if (!await this.isExecutable(candidate)) {
128
+ continue;
129
+ }
130
+ const target = await fs_1.promises.realpath(candidate).catch(() => candidate);
131
+ for (const mapped of this.toCandidatesOnPath(target)) {
132
+ if (await this.isExecutable(mapped)) {
133
+ return mapped;
134
+ }
135
+ }
136
+ // A launcher that leads nowhere is not usable: it cannot be spawned without a Node.js, and
137
+ // a Windows shim cannot be spawned without a shell, which the Copilot SDK does not do either.
138
+ if (!this.isLauncher(candidate)) {
139
+ return candidate;
140
+ }
141
+ }
142
+ return undefined;
143
+ }
144
+ /**
145
+ * The location given in the environment, resolved the same way as a configured one.
146
+ *
147
+ * The variable is documented as doing what the preference does, so a directory or a launcher is
148
+ * accepted here as well. A value that leads nowhere is reported and then left behind rather than
149
+ * turned into an error, so that the remaining sources still get their chance.
150
+ */
151
+ async environmentCandidates() {
152
+ const configured = process.env[exports.COPILOT_CLI_PATH_ENV]?.trim();
153
+ if (!configured) {
154
+ return [];
155
+ }
156
+ const resolved = await this.resolveConfiguredPath(configured);
157
+ if (resolved) {
158
+ return [resolved];
159
+ }
160
+ // A launcher that could not be followed is dropped rather than kept as a candidate, because it
161
+ // would be spawned and cannot work. Everything else is kept, so that the error names it.
162
+ this.logger.warn(`Copilot: ${exports.COPILOT_CLI_PATH_ENV} does not point at a usable Copilot CLI: ${configured}`);
163
+ return this.isLauncher(configured) ? [] : [configured];
164
+ }
165
+ /**
166
+ * The executable of a platform package that was installed alongside this application, if any.
167
+ *
168
+ * Both the module paths of this file and those of the Copilot SDK are searched, so that the
169
+ * package is found whether the installation hoisted it or nested it below the SDK.
170
+ */
171
+ async bundledCandidates() {
172
+ const candidates = [...this.resolvedCandidates(__filename)];
173
+ try {
174
+ const resolver = (0, module_1.createRequire)(__filename);
175
+ candidates.push(...this.resolvedCandidates(resolver.resolve('@github/copilot-sdk')));
176
+ for (const base of resolver.resolve.paths('@github/copilot') ?? []) {
177
+ candidates.push(...this.toPlatformPackageCandidates(base));
178
+ }
179
+ }
180
+ catch (error) {
181
+ // The SDK is not installed next to us; what was resolved from this file remains.
182
+ }
183
+ return candidates;
184
+ }
185
+ /**
186
+ * The executable of a platform package as Node.js resolves it from the given file.
187
+ *
188
+ * This is how the launcher of the CLI finds its own executable, and it is the only lookup that
189
+ * covers every layout: an installation hoists the platform package next to the launcher, while a
190
+ * global installation nests it below the launcher instead. The package points its main entry at
191
+ * the executable, so the directory of what was resolved is the directory holding it.
192
+ */
193
+ resolvedCandidates(anchor) {
194
+ const candidates = [];
195
+ for (const packageName of this.getCliPlatformPackageNames()) {
196
+ try {
197
+ candidates.push((0, path_1.join)((0, path_1.dirname)((0, module_1.createRequire)(anchor).resolve(packageName)), this.getBinaryName()));
198
+ }
199
+ catch (error) {
200
+ // No such package below this anchor.
201
+ }
202
+ }
203
+ return candidates;
204
+ }
205
+ /**
206
+ * The executable of a CLI that is on the `PATH` of the backend process.
207
+ *
208
+ * A global npm installation does not put the executable itself there but a launcher: a link to
209
+ * the JavaScript entry point on Linux and macOS, and a `.cmd` shim on Windows. Such a hit is
210
+ * therefore mapped to the platform package it belongs to, see {@link toCandidatesOnPath}.
211
+ */
212
+ async pathCandidates() {
213
+ const candidates = [];
214
+ for (const entry of (process.env.PATH ?? '').split(path_1.delimiter)) {
215
+ if (!entry) {
216
+ continue;
217
+ }
218
+ for (const name of this.getCliFileNames()) {
219
+ const candidate = (0, path_1.join)(entry, name);
220
+ try {
221
+ candidates.push(...this.toCandidatesOnPath(await fs_1.promises.realpath(candidate)));
222
+ }
223
+ catch (error) {
224
+ // No CLI of this name in this entry of the PATH.
225
+ }
226
+ }
227
+ }
228
+ return candidates;
229
+ }
230
+ /**
231
+ * Interprets what a `copilot` on the `PATH` points at: a launcher of a global npm installation is
232
+ * mapped to the executable of the platform package it would start, anything else is taken to be
233
+ * the executable itself.
234
+ */
235
+ toCandidatesOnPath(target) {
236
+ if (this.isJsEntryPoint(target)) {
237
+ // `<node_modules>/@github/copilot/npm-loader.js`, so resolve from the launcher itself and
238
+ // fall back to `<node_modules>`, which is where a hoisting installation puts the package.
239
+ return [...this.resolvedCandidates(target), ...this.moduleDirectoryCandidates((0, path_1.dirname)((0, path_1.dirname)((0, path_1.dirname)(target))))];
240
+ }
241
+ if (this.isShim(target)) {
242
+ // `<npm prefix>/copilot.cmd` on Windows, which is not a link to the entry point but a batch
243
+ // file next to the module directory the installation wrote.
244
+ return this.moduleDirectoryCandidates((0, path_1.join)((0, path_1.dirname)(target), 'node_modules'));
245
+ }
246
+ return [target];
247
+ }
248
+ /**
249
+ * The executable of a globally installed CLI, for the case that the global binary directory is
250
+ * not on the `PATH` of the backend process. That is common when the application was started from
251
+ * a desktop launcher rather than from a shell.
252
+ */
253
+ async globalInstallCandidates() {
254
+ try {
255
+ // Through a shell on Windows, where `npm` is a `.cmd` that cannot be spawned directly.
256
+ const { stdout } = await execFileAsync('npm', ['root', '-g'], {
257
+ timeout: NPM_ROOT_TIMEOUT_MS,
258
+ windowsHide: true,
259
+ shell: process.platform === 'win32'
260
+ });
261
+ return this.moduleDirectoryCandidates(stdout.trim());
262
+ }
263
+ catch (error) {
264
+ this.logger.debug('Copilot: could not determine the global npm directory:', error);
265
+ return [];
266
+ }
267
+ }
268
+ /**
269
+ * The executables a module directory can hold the CLI in.
270
+ *
271
+ * A global installation nests the platform package below the launcher rather than hoisting it, so
272
+ * the launcher is used to resolve from, and the hoisted layout is tried as well.
273
+ */
274
+ moduleDirectoryCandidates(modules) {
275
+ if (!modules) {
276
+ return [];
277
+ }
278
+ return [
279
+ ...this.resolvedCandidates((0, path_1.join)(modules, '@github', 'copilot', 'npm-loader.js')),
280
+ ...this.toPlatformPackageCandidates(modules)
281
+ ];
282
+ }
283
+ /**
284
+ * The executables the platform packages of this host would have below the given module directory.
285
+ */
286
+ toPlatformPackageCandidates(base) {
287
+ if (!base) {
288
+ return [];
289
+ }
290
+ return this.getCliPlatformPackageNames().map(packageName => (0, path_1.join)(base, ...packageName.split('/'), this.getBinaryName()));
291
+ }
292
+ /**
293
+ * The platform-specific packages that can carry the CLI for this host.
294
+ * On Linux both the glibc and the musl build are candidates.
295
+ */
296
+ getCliPlatformPackageNames() {
297
+ const variants = process.platform === 'linux' ? ['linux', 'linuxmusl'] : [process.platform];
298
+ return variants.map(variant => `@github/copilot-${variant}-${process.arch}`);
299
+ }
300
+ getBinaryName() {
301
+ return process.platform === 'win32' ? 'copilot.exe' : 'copilot';
302
+ }
303
+ /**
304
+ * The names a CLI can go by in a directory that is on the `PATH` or that a user configured: the
305
+ * executable itself, and on Windows in addition the shim a global npm installation writes, since
306
+ * that is the only entry it puts there.
307
+ */
308
+ getCliFileNames() {
309
+ return process.platform === 'win32' ? [this.getBinaryName(), 'copilot.cmd'] : [this.getBinaryName()];
310
+ }
311
+ /**
312
+ * Whether the given path is something that starts the CLI rather than the CLI itself, which is
313
+ * either its JavaScript entry point or a shim of a global installation.
314
+ */
315
+ isLauncher(path) {
316
+ return this.isJsEntryPoint(path) || this.isShim(path);
317
+ }
318
+ isJsEntryPoint(path) {
319
+ return path.endsWith('.js') || path.endsWith('.mjs');
320
+ }
321
+ isShim(path) {
322
+ return /\.(cmd|bat|ps1)$/i.test(path);
323
+ }
324
+ async isExecutable(path) {
325
+ try {
326
+ const stats = await fs_1.promises.stat(path);
327
+ if (!stats.isFile()) {
328
+ return false;
329
+ }
330
+ // The executable bit is not modelled on Windows, where every file passes this check.
331
+ await fs_1.promises.access(path, fs_1.constants.X_OK);
332
+ return true;
333
+ }
334
+ catch (error) {
335
+ return false;
336
+ }
337
+ }
338
+ };
339
+ exports.CopilotCliLocator = CopilotCliLocator;
340
+ tslib_1.__decorate([
341
+ (0, inversify_1.inject)(core_1.ILogger),
342
+ (0, inversify_1.named)('ai-copilot:CopilotCliLocator'),
343
+ tslib_1.__metadata("design:type", Object)
344
+ ], CopilotCliLocator.prototype, "logger", void 0);
345
+ exports.CopilotCliLocator = CopilotCliLocator = tslib_1.__decorate([
346
+ (0, inversify_1.injectable)()
347
+ ], CopilotCliLocator);
348
+ //# sourceMappingURL=copilot-cli-locator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"copilot-cli-locator.js","sourceRoot":"","sources":["../../src/node/copilot-cli-locator.ts"],"names":[],"mappings":";AAAA,gFAAgF;AAChF,oDAAoD;AACpD,EAAE;AACF,2EAA2E;AAC3E,mEAAmE;AACnE,wCAAwC;AACxC,EAAE;AACF,4EAA4E;AAC5E,8EAA8E;AAC9E,6EAA6E;AAC7E,yDAAyD;AACzD,uDAAuD;AACvD,EAAE;AACF,gFAAgF;AAChF,gFAAgF;;;;AAEhF,iDAAyC;AACzC,2BAA+C;AAC/C,mCAAuC;AACvC,+BAAgD;AAChD,+BAAiC;AACjC,4DAAyE;AACzE,sCAA2C;AAE3C,MAAM,aAAa,GAAG,IAAA,gBAAS,EAAC,wBAAQ,CAAC,CAAC;AAE1C;;GAEG;AACU,QAAA,oBAAoB,GAAG,kBAAkB,CAAC;AAEvD;;GAEG;AACH,MAAM,mBAAmB,GAAG,KAAK,CAAC;AAElC;;;;;;;;;;;;;GAaG;AAEI,IAAM,iBAAiB,GAAvB,MAAM,iBAAiB;IAQ1B;;;OAGG;IACH,iBAAiB,CAAC,IAAwB;QACtC,MAAM,UAAU,GAAG,IAAI,EAAE,IAAI,EAAE,IAAI,SAAS,CAAC;QAC7C,IAAI,UAAU,KAAK,IAAI,CAAC,cAAc,EAAE,CAAC;YACrC,IAAI,CAAC,cAAc,GAAG,UAAU,CAAC;YACjC,IAAI,CAAC,UAAU,GAAG,SAAS,CAAC;QAChC,CAAC;IACL,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,OAAO;QACT,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC;YACnB,MAAM,UAAU,GAAG,IAAI,CAAC,SAAS,EAAE,CAAC;YACpC,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;YAC7B,yFAAyF;YACzF,qEAAqE;YACrE,UAAU,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CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAC1D,CAAC;IAES,cAAc,CAAC,IAAY;QACjC,OAAO,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IACzD,CAAC;IAES,MAAM,CAAC,IAAY;QACzB,OAAO,mBAAmB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC1C,CAAC;IAES,KAAK,CAAC,YAAY,CAAC,IAAY;QACrC,IAAI,CAAC;YACD,MAAM,KAAK,GAAG,MAAM,aAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAClC,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,EAAE,CAAC;gBAClB,OAAO,KAAK,CAAC;YACjB,CAAC;YACD,qFAAqF;YACrF,MAAM,aAAE,CAAC,MAAM,CAAC,IAAI,EAAE,cAAS,CAAC,IAAI,CAAC,CAAC;YACtC,OAAO,IAAI,CAAC;QAChB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACb,OAAO,KAAK,CAAC;QACjB,CAAC;IACL,CAAC;CACJ,CAAA;AAvTY,8CAAiB;AAGP;IADlB,IAAA,kBAAM,EAAC,cAAO,CAAC;IAAE,IAAA,iBAAK,EAAC,8BAA8B,CAAC;;iDACpB;4BAH1B,iBAAiB;IAD7B,IAAA,sBAAU,GAAE;GACA,iBAAiB,CAuT7B"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=copilot-cli-locator.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"copilot-cli-locator.spec.d.ts","sourceRoot":"","sources":["../../src/node/copilot-cli-locator.spec.ts"],"names":[],"mappings":""}