imcp 0.1.4 → 0.1.6

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 (57) hide show
  1. package/.github/workflows/build.yml +28 -0
  2. package/README.md +21 -4
  3. package/dist/cli/commands/start.d.ts +2 -0
  4. package/dist/cli/commands/start.js +32 -0
  5. package/dist/cli/commands/sync.d.ts +2 -0
  6. package/dist/cli/commands/sync.js +17 -0
  7. package/dist/cli/index.js +0 -0
  8. package/dist/core/ConfigurationLoader.d.ts +32 -0
  9. package/dist/core/ConfigurationLoader.js +236 -0
  10. package/dist/core/ConfigurationProvider.d.ts +35 -0
  11. package/dist/core/ConfigurationProvider.js +375 -0
  12. package/dist/core/InstallationService.d.ts +50 -0
  13. package/dist/core/InstallationService.js +350 -0
  14. package/dist/core/MCPManager.d.ts +28 -0
  15. package/dist/core/MCPManager.js +188 -0
  16. package/dist/core/RequirementService.d.ts +40 -0
  17. package/dist/core/RequirementService.js +110 -0
  18. package/dist/core/ServerSchemaLoader.d.ts +11 -0
  19. package/dist/core/ServerSchemaLoader.js +43 -0
  20. package/dist/core/ServerSchemaProvider.d.ts +17 -0
  21. package/dist/core/ServerSchemaProvider.js +120 -0
  22. package/dist/core/constants.d.ts +47 -0
  23. package/dist/core/constants.js +94 -0
  24. package/dist/core/installers/BaseInstaller.d.ts +74 -0
  25. package/dist/core/installers/BaseInstaller.js +253 -0
  26. package/dist/core/installers/ClientInstaller.d.ts +23 -0
  27. package/dist/core/installers/ClientInstaller.js +564 -0
  28. package/dist/core/installers/CommandInstaller.d.ts +37 -0
  29. package/dist/core/installers/CommandInstaller.js +173 -0
  30. package/dist/core/installers/GeneralInstaller.d.ts +33 -0
  31. package/dist/core/installers/GeneralInstaller.js +85 -0
  32. package/dist/core/installers/InstallerFactory.d.ts +54 -0
  33. package/dist/core/installers/InstallerFactory.js +97 -0
  34. package/dist/core/installers/NpmInstaller.d.ts +26 -0
  35. package/dist/core/installers/NpmInstaller.js +127 -0
  36. package/dist/core/installers/PipInstaller.d.ts +28 -0
  37. package/dist/core/installers/PipInstaller.js +127 -0
  38. package/dist/core/installers/RequirementInstaller.d.ts +33 -0
  39. package/dist/core/installers/RequirementInstaller.js +3 -0
  40. package/dist/core/types.d.ts +166 -0
  41. package/dist/core/types.js +16 -0
  42. package/dist/services/InstallRequestValidator.d.ts +21 -0
  43. package/dist/services/InstallRequestValidator.js +99 -0
  44. package/dist/web/public/index.html +1 -1
  45. package/dist/web/public/js/modal/installHandler.js +227 -0
  46. package/dist/web/public/js/modal/loadingUI.js +74 -0
  47. package/dist/web/public/js/modal/messageQueue.js +101 -45
  48. package/dist/web/public/js/modal/modalUI.js +214 -0
  49. package/dist/web/public/js/modal/version.js +20 -0
  50. package/dist/web/public/onboard.html +4 -4
  51. package/package.json +1 -1
  52. package/src/web/public/index.html +1 -1
  53. package/src/web/public/onboard.html +4 -4
  54. package/wiki/Installation.md +3 -0
  55. package/wiki/Publish.md +3 -0
  56. package/dist/core/onboard/InstallOperationManager.d.ts +0 -23
  57. package/dist/core/onboard/InstallOperationManager.js +0 -144
@@ -0,0 +1,564 @@
1
+ import { GetBrowserPath } from '../../utils/osUtils.js';
2
+ import { ConfigurationProvider } from '../ConfigurationProvider.js';
3
+ import { SUPPORTED_CLIENTS } from '../constants.js';
4
+ import { resolveNpmModulePath, readJsonFile, writeJsonFile } from '../../utils/clientUtils.js';
5
+ import { exec } from 'child_process';
6
+ import { promisify } from 'util';
7
+ import { Logger } from '../../utils/logger.js';
8
+ import { getPythonPackagePath, getSystemPythonPackageDirectory } from '../../utils/osUtils.js';
9
+ const execAsync = promisify(exec); // Moved promisify here for reuse
10
+ export class ClientInstaller {
11
+ categoryName;
12
+ serverName;
13
+ clients;
14
+ configProvider;
15
+ operationStatuses;
16
+ constructor(categoryName, serverName, clients) {
17
+ this.categoryName = categoryName;
18
+ this.serverName = serverName;
19
+ this.clients = clients;
20
+ this.configProvider = ConfigurationProvider.getInstance();
21
+ this.operationStatuses = new Map();
22
+ }
23
+ generateOperationId() {
24
+ return `install-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
25
+ }
26
+ async getNpmPath() {
27
+ try {
28
+ // Execute the get-command npm command to find the npm path
29
+ const { stdout } = await execAsync('powershell -Command "get-command npm | Select-Object -ExpandProperty Source"');
30
+ // Extract the directory from the full path (removing npm.cmd)
31
+ const npmPath = stdout.trim().replace(/\\npm\.cmd$/, '');
32
+ return npmPath;
33
+ }
34
+ catch (error) {
35
+ console.error('Error getting npm path:', error);
36
+ // Return a default path if the command fails
37
+ return 'C:\\Program Files\\nodejs';
38
+ }
39
+ }
40
+ /**
41
+ * Check if a command is available on the system
42
+ * @param command The command to check
43
+ * @returns True if the command is available, false otherwise
44
+ */
45
+ async isCommandAvailable(command) {
46
+ try {
47
+ if (process.platform === 'win32') {
48
+ // Windows-specific command check
49
+ await execAsync(`where ${command}`);
50
+ }
51
+ else if (process.platform === 'darwin' && (command === 'code' || command === 'code-insiders')) {
52
+ // macOS-specific VS Code check
53
+ const vscodePath = command === 'code' ?
54
+ '/Applications/Visual Studio Code.app' :
55
+ '/Applications/Visual Studio Code - Insiders.app';
56
+ await execAsync(`test -d "${vscodePath}"`);
57
+ }
58
+ else {
59
+ // Unix-like systems
60
+ await execAsync(`which ${command}`);
61
+ }
62
+ return true;
63
+ }
64
+ catch (error) {
65
+ if (process.platform === 'darwin' && (command === 'code' || command === 'code-insiders')) {
66
+ // Try checking in ~/Applications as well for macOS
67
+ try {
68
+ const homedir = process.env.HOME;
69
+ const vscodePath = command === 'code' ?
70
+ `${homedir}/Applications/Visual Studio Code.app` :
71
+ `${homedir}/Applications/Visual Studio Code - Insiders.app`;
72
+ await execAsync(`test -d "${vscodePath}"`);
73
+ return true;
74
+ }
75
+ catch (error) {
76
+ return false;
77
+ }
78
+ }
79
+ return false;
80
+ }
81
+ }
82
+ // Modified to accept ServerInstallOptions
83
+ async installClient(clientName, options) {
84
+ // Check if client is supported
85
+ if (!SUPPORTED_CLIENTS[clientName]) {
86
+ return {
87
+ status: 'failed',
88
+ type: 'install',
89
+ target: 'server',
90
+ message: `Unsupported client: ${clientName}`,
91
+ operationId: this.generateOperationId()
92
+ };
93
+ }
94
+ // Create initial operation status
95
+ const operationId = this.generateOperationId();
96
+ const initialStatus = {
97
+ status: 'pending',
98
+ type: 'install',
99
+ target: 'server',
100
+ message: `Initializing installation for client: ${clientName}`,
101
+ operationId: operationId
102
+ };
103
+ // Update server status with initial client installation status
104
+ await this.configProvider.updateServerOperationStatus(this.categoryName, this.serverName, clientName, initialStatus);
105
+ // Start the asynchronous installation process without awaiting it
106
+ // Pass options down
107
+ this.processInstallation(clientName, operationId, options);
108
+ // Return the initial status immediately
109
+ return initialStatus;
110
+ }
111
+ // Modified to accept ServerInstallOptions
112
+ async processInstallation(clientName, operationId, options) {
113
+ try {
114
+ // Check requirements before installation
115
+ let requirementsReady = await this.configProvider.isRequirementsReady(this.categoryName, this.serverName);
116
+ // If requirements are not ready, periodically check with timeout
117
+ if (!requirementsReady) {
118
+ const pendingStatus = {
119
+ status: 'pending',
120
+ type: 'install',
121
+ target: 'server',
122
+ message: `Waiting for requirements to be ready for client: ${clientName}`,
123
+ operationId: operationId
124
+ };
125
+ // Update status to pending with reference to configProvider
126
+ await this.configProvider.updateServerOperationStatus(this.categoryName, this.serverName, clientName, pendingStatus);
127
+ // Set up periodic checking with timeout
128
+ const startTime = Date.now();
129
+ const timeoutMs = 5 * 60 * 1000; // 5 minutes in milliseconds
130
+ const intervalMs = 5 * 1000; // 5 seconds in milliseconds
131
+ while (!requirementsReady && (Date.now() - startTime) < timeoutMs) {
132
+ // Wait for the interval
133
+ await new Promise(resolve => setTimeout(resolve, intervalMs));
134
+ // Check again
135
+ requirementsReady = await this.configProvider.isRequirementsReady(this.categoryName, this.serverName);
136
+ }
137
+ // If still not ready after timeout, update status as failed and exit
138
+ if (!requirementsReady) {
139
+ const failedStatus = {
140
+ status: 'failed',
141
+ type: 'install',
142
+ target: 'server',
143
+ message: `Timed out waiting for requirements to be ready for client: ${clientName} after 5 minutes`,
144
+ operationId: operationId
145
+ };
146
+ await this.configProvider.updateServerOperationStatus(this.categoryName, this.serverName, clientName, failedStatus);
147
+ return; // Exit the installation process
148
+ }
149
+ }
150
+ // If we've reached here, requirements are ready - update status to in-progress
151
+ const inProgressStatus = {
152
+ status: 'in-progress',
153
+ type: 'install',
154
+ target: 'server',
155
+ message: `Installing client: ${clientName}`,
156
+ operationId: operationId
157
+ };
158
+ await this.configProvider.updateServerOperationStatus(this.categoryName, this.serverName, clientName, inProgressStatus);
159
+ // Get feed configuration for the server
160
+ const feedConfiguration = await this.configProvider.getFeedConfiguration(this.categoryName);
161
+ if (!feedConfiguration) {
162
+ const errorStatus = {
163
+ status: 'failed',
164
+ type: 'install',
165
+ target: 'server',
166
+ message: `Failed to get feed configuration for category: ${this.categoryName}`,
167
+ operationId: operationId
168
+ };
169
+ await this.configProvider.updateServerOperationStatus(this.categoryName, this.serverName, clientName, errorStatus);
170
+ return;
171
+ }
172
+ // Find the server config in the feed configuration
173
+ const serverConfig = feedConfiguration.mcpServers.find(s => s.name === this.serverName);
174
+ if (!serverConfig) {
175
+ const errorStatus = {
176
+ status: 'failed',
177
+ type: 'install',
178
+ target: 'server',
179
+ message: `Server ${this.serverName} not found in feed configuration`,
180
+ operationId: operationId
181
+ };
182
+ await this.configProvider.updateServerOperationStatus(this.categoryName, this.serverName, clientName, errorStatus);
183
+ return;
184
+ }
185
+ try {
186
+ // Install client-specific configuration, passing options down
187
+ const result = await this.installClientConfig(clientName, options, serverConfig, feedConfiguration);
188
+ const finalStatus = {
189
+ status: result.success ? 'completed' : 'failed',
190
+ type: 'install',
191
+ target: 'server',
192
+ message: result.message || `Installation for client ${clientName}: ${result.success ? 'successful' : 'failed'}`,
193
+ operationId: operationId,
194
+ error: result.success ? undefined : result.message
195
+ };
196
+ await this.configProvider.updateServerOperationStatus(this.categoryName, this.serverName, clientName, finalStatus);
197
+ if (result.success) {
198
+ await this.configProvider.reloadClientMCPSettings();
199
+ }
200
+ }
201
+ catch (error) {
202
+ const errorStatus = {
203
+ status: 'failed',
204
+ type: 'install',
205
+ target: 'server',
206
+ message: `Failed to install client: ${clientName}. Error: ${error instanceof Error ? error.message : String(error)}`,
207
+ operationId: operationId,
208
+ error: error instanceof Error ? error.message : String(error)
209
+ };
210
+ await this.configProvider.updateServerOperationStatus(this.categoryName, this.serverName, clientName, errorStatus);
211
+ }
212
+ }
213
+ catch (error) {
214
+ const errorStatus = {
215
+ status: 'failed',
216
+ type: 'install',
217
+ target: 'server',
218
+ message: `Unexpected error in installation process for client: ${clientName}. Error: ${error instanceof Error ? error.message : String(error)}`,
219
+ operationId: operationId,
220
+ error: error instanceof Error ? error.message : String(error)
221
+ };
222
+ await this.configProvider.updateServerOperationStatus(this.categoryName, this.serverName, clientName, errorStatus);
223
+ }
224
+ }
225
+ // Modified to accept ServerInstallOptions
226
+ async installClientConfig(clientName, options, // Use options directly
227
+ serverConfig, feedConfig) {
228
+ try {
229
+ if (!SUPPORTED_CLIENTS[clientName]) {
230
+ Logger.debug(`Client ${clientName} is not supported.`);
231
+ return { success: false, message: `Unsupported client: ${clientName}` };
232
+ }
233
+ const clientSettings = SUPPORTED_CLIENTS[clientName];
234
+ // Get both setting paths for VS Code and VS Code Insiders
235
+ const regularSettingPath = clientSettings.codeSettingPath;
236
+ const insidersSettingPath = clientSettings.codeInsiderSettingPath;
237
+ Logger.debug(`Starting installation of ${this.serverName} for client ${clientName}`);
238
+ Logger.debug(`VS Code settings path configured as: ${regularSettingPath}`);
239
+ Logger.debug(`VS Code Insiders settings path configured as: ${insidersSettingPath}`);
240
+ // Check if VS Code and VS Code Insiders are installed
241
+ const isVSCodeInstalled = await this.isCommandAvailable('code');
242
+ const isVSCodeInsidersInstalled = await this.isCommandAvailable('code-insiders');
243
+ Logger.debug(isVSCodeInstalled ? 'VS Code detected on system' : 'VS Code not detected on system');
244
+ Logger.debug(isVSCodeInsidersInstalled ? 'VS Code Insiders detected on system' : 'VS Code Insiders not detected on system');
245
+ // If neither is installed, we can't proceed
246
+ if (!isVSCodeInstalled && !isVSCodeInsidersInstalled) {
247
+ Logger.debug('No VS Code installations detected on system. Cannot update settings.');
248
+ return {
249
+ success: false,
250
+ message: `Neither VS Code nor VS Code Insiders are installed on this system. Cannot update settings for client: ${clientName}. Please install VS Code or VS Code Insiders and try again.`
251
+ };
252
+ }
253
+ // --- Start of new logic ---
254
+ // Clone the base installation configuration to avoid modifying the original serverConfig
255
+ const installConfig = JSON.parse(JSON.stringify(serverConfig.installation));
256
+ const pythonEnv = options.settings?.pythonEnv;
257
+ let pythonDir = null;
258
+ // 1. Determine which args to use and resolve npm paths
259
+ let finalArgs = [];
260
+ if (options.args && options.args.length > 0) {
261
+ Logger.debug(`Using args from ServerInstallOptions: ${options.args.join(' ')}`);
262
+ finalArgs = options.args.map(arg => resolveNpmModulePath(arg));
263
+ }
264
+ else if (installConfig.args && installConfig.args.length > 0) {
265
+ Logger.debug(`Using args from serverConfig.installation: ${installConfig.args.join(' ')}`);
266
+ finalArgs = installConfig.args.map((arg) => resolveNpmModulePath(arg));
267
+ }
268
+ else {
269
+ Logger.debug('No args found in options or serverConfig.installation.');
270
+ finalArgs = [];
271
+ }
272
+ // 2. Handle pythonEnv settings
273
+ if (pythonEnv) {
274
+ // 2.1 If pythonEnv is set
275
+ Logger.debug(`Python environment specified: ${pythonEnv}`);
276
+ pythonDir = getPythonPackagePath(pythonEnv);
277
+ // 2.1.1 Replace ${PYTHON_PACKAGE} in args
278
+ if (pythonDir) {
279
+ finalArgs = finalArgs.map(arg => arg.includes('${PYTHON_PACKAGE}') ? arg.replace('${PYTHON_PACKAGE}', pythonDir) : arg);
280
+ Logger.debug(`Args after PYTHON_PACKAGE replacement (using pythonEnv): ${finalArgs.join(' ')}`);
281
+ }
282
+ else {
283
+ Logger.debug(`Could not determine directory for pythonEnv: ${pythonEnv}`);
284
+ }
285
+ // 2.1.2 Replace command if it's 'python'
286
+ if (installConfig.command === 'python') {
287
+ Logger.debug(`Replacing command 'python' with specified pythonEnv: ${pythonEnv}`);
288
+ installConfig.command = pythonEnv;
289
+ }
290
+ }
291
+ else {
292
+ // 2.2 If pythonEnv is not set
293
+ Logger.debug('No Python environment specified in settings.');
294
+ // 2.2.1 Replace ${PYTHON_PACKAGE} with system python directory if needed
295
+ if (finalArgs.some(arg => arg.includes('${PYTHON_PACKAGE}'))) {
296
+ Logger.debug('Attempting to find system Python directory for ${PYTHON_PACKAGE} replacement.');
297
+ pythonDir = await getSystemPythonPackageDirectory();
298
+ if (pythonDir) {
299
+ finalArgs = finalArgs.map(arg => arg.includes('${PYTHON_PACKAGE}') ? arg.replace('${PYTHON_PACKAGE}', pythonDir) : arg);
300
+ Logger.debug(`Args after PYTHON_PACKAGE replacement (using system python): ${finalArgs.join(' ')}`);
301
+ }
302
+ else {
303
+ Logger.debug('Could not find system Python directory. ${PYTHON_PACKAGE} replacement skipped.');
304
+ // Optionally, remove or handle the arg containing ${PYTHON_PACKAGE} if Python is required
305
+ // finalArgs = finalArgs.filter(arg => !arg.includes('${PYTHON_PACKAGE}'));
306
+ }
307
+ }
308
+ }
309
+ // Update installConfig with potentially modified args
310
+ installConfig.args = finalArgs;
311
+ // 3. Handle environment variables (merge default, serverConfig, and options.env)
312
+ const baseEnv = serverConfig.installation.env || {};
313
+ const defaultEnv = {};
314
+ for (const [key, config] of Object.entries(baseEnv)) {
315
+ const envConfig = config; // Type assertion
316
+ if (envConfig.Default) {
317
+ defaultEnv[key] = envConfig.Default;
318
+ }
319
+ }
320
+ // Merge: options.env overrides defaultEnv
321
+ installConfig.env = { ...defaultEnv, ...(options.env || {}) };
322
+ // Replace ${BROWSER_PATH} with actual browser path
323
+ const replacements = Object.entries(installConfig.env)
324
+ .filter(([_, value]) => typeof value === 'string' && value.includes('${BROWSER_PATH}'))
325
+ .map(async ([key, value]) => {
326
+ try {
327
+ const browserPath = await GetBrowserPath();
328
+ return [key, value.replace('${BROWSER_PATH}', browserPath)];
329
+ }
330
+ catch (error) {
331
+ Logger.error(`Failed to get system browser path for env var ${key}:`, error);
332
+ return [key, value];
333
+ }
334
+ });
335
+ // Wait for all replacements to complete
336
+ const replacedValues = await Promise.all(replacements);
337
+ replacedValues.forEach(([key, value]) => {
338
+ installConfig.env[key] = value;
339
+ });
340
+ Logger.debug(`Final environment variables: ${JSON.stringify(installConfig.env)}`);
341
+ // --- End of new logic ---
342
+ // Keep track of success for both installations
343
+ let regularSuccess = false;
344
+ let insidersSuccess = false;
345
+ let errorMessages = [];
346
+ // Update client-specific settings for both VS Code and VS Code Insiders
347
+ if (clientName === 'MSRooCode' || clientName === 'Cline') {
348
+ // Update VS Code settings if VS Code is installed
349
+ if (isVSCodeInstalled) {
350
+ try {
351
+ Logger.debug(`Updating VS Code settings for ${clientName} at path: ${regularSettingPath}`);
352
+ // Pass the modified installConfig
353
+ await this.updateClineOrMSRooSettings(regularSettingPath, this.serverName, installConfig, clientName);
354
+ regularSuccess = true;
355
+ Logger.debug(`Settings successfully updated to ${regularSettingPath} for ${clientName} (VS Code)`);
356
+ }
357
+ catch (error) {
358
+ const errorMsg = `Error updating VS Code settings: ${error instanceof Error ? error.message : String(error)}`;
359
+ errorMessages.push(errorMsg);
360
+ console.error(errorMsg);
361
+ }
362
+ }
363
+ // Update VS Code Insiders settings if VS Code Insiders is installed
364
+ if (isVSCodeInsidersInstalled) {
365
+ try {
366
+ Logger.debug(`Updating VS Code Insiders settings for ${clientName} at path: ${insidersSettingPath}`);
367
+ // Pass the modified installConfig
368
+ await this.updateClineOrMSRooSettings(insidersSettingPath, this.serverName, installConfig, clientName);
369
+ insidersSuccess = true;
370
+ Logger.debug(`Settings successfully updated to ${insidersSettingPath} for ${clientName} (VS Code Insiders)`);
371
+ }
372
+ catch (error) {
373
+ const errorMsg = `Error updating VS Code Insiders settings: ${error instanceof Error ? error.message : String(error)}`;
374
+ errorMessages.push(errorMsg);
375
+ console.error(errorMsg);
376
+ }
377
+ }
378
+ }
379
+ else if (clientName === 'GithubCopilot') {
380
+ // Update VS Code settings if VS Code is installed
381
+ if (isVSCodeInstalled) {
382
+ try {
383
+ Logger.debug(`Updating VS Code settings for ${clientName} at path: ${regularSettingPath}`);
384
+ // Pass the modified installConfig
385
+ await this.updateGithubCopilotSettings(regularSettingPath, this.serverName, installConfig);
386
+ regularSuccess = true;
387
+ Logger.debug(`Settings successfully updated to ${regularSettingPath} for ${clientName} (VS Code)`);
388
+ }
389
+ catch (error) {
390
+ const errorMsg = `Error updating VS Code settings: ${error instanceof Error ? error.message : String(error)}`;
391
+ errorMessages.push(errorMsg);
392
+ console.error(errorMsg);
393
+ }
394
+ }
395
+ // Update VS Code Insiders settings if VS Code Insiders is installed
396
+ if (isVSCodeInsidersInstalled) {
397
+ try {
398
+ Logger.debug(`Updating VS Code Insiders settings for ${clientName} at path: ${insidersSettingPath}`);
399
+ // Pass the modified installConfig
400
+ await this.updateGithubCopilotSettings(insidersSettingPath, this.serverName, installConfig);
401
+ insidersSuccess = true;
402
+ Logger.debug(`Settings successfully updated to ${insidersSettingPath} for ${clientName} (VS Code Insiders)`);
403
+ }
404
+ catch (error) {
405
+ const errorMsg = `Error updating VS Code Insiders settings: ${error instanceof Error ? error.message : String(error)}`;
406
+ errorMessages.push(errorMsg);
407
+ console.error(errorMsg);
408
+ }
409
+ }
410
+ }
411
+ else {
412
+ Logger.debug(`No implementation exists for updating settings for client: ${clientName}`);
413
+ return {
414
+ success: false,
415
+ message: `Client ${clientName} is supported but no implementation exists for updating its settings`
416
+ };
417
+ }
418
+ // Determine overall success status and message
419
+ const overallSuccess = regularSuccess || insidersSuccess;
420
+ let message = '';
421
+ if (overallSuccess) {
422
+ const successDetails = [];
423
+ if (regularSuccess)
424
+ successDetails.push('VS Code');
425
+ if (insidersSuccess)
426
+ successDetails.push('VS Code Insiders');
427
+ // Create a more compact success message with specific paths
428
+ const pathDetails = [];
429
+ if (regularSuccess) {
430
+ pathDetails.push(`\n[VS Code]: ${regularSettingPath}`);
431
+ }
432
+ if (insidersSuccess) {
433
+ pathDetails.push(`\n[VS Code Insiders]: ${insidersSettingPath}`);
434
+ }
435
+ message = `Successfully installed ${this.serverName} for client: ${clientName}. ${pathDetails.join(' ')}`;
436
+ // Add partial failure information if applicable
437
+ if (errorMessages.length > 0) {
438
+ message += `\nHowever, some errors occurred:\n${errorMessages.join('\n- ')}`;
439
+ }
440
+ Logger.debug(`Installation complete: ${message}`);
441
+ }
442
+ else {
443
+ // Create a more detailed failure message that includes the detection results
444
+ const detectionInfo = [];
445
+ if (!isVSCodeInstalled)
446
+ detectionInfo.push('VS Code not detected');
447
+ if (!isVSCodeInsidersInstalled)
448
+ detectionInfo.push('VS Code Insiders not detected');
449
+ if (errorMessages.length > 0) {
450
+ message = `Failed to install ${this.serverName} for client: ${clientName}.\nDetection status: [${detectionInfo.join(', ')}].\nErrors:\n- ${errorMessages.join('\n- ')}`;
451
+ }
452
+ else {
453
+ message = `Failed to install ${this.serverName} for client: ${clientName}.\nDetection status: [${detectionInfo.join(', ')}]`;
454
+ }
455
+ console.error(`Installation failed: ${message}`);
456
+ }
457
+ return {
458
+ success: overallSuccess,
459
+ message: message
460
+ };
461
+ }
462
+ catch (error) {
463
+ const errorMsg = `Error installing client ${clientName}: ${error instanceof Error ? error.message : String(error)}`;
464
+ console.error(errorMsg);
465
+ return {
466
+ success: false,
467
+ message: errorMsg
468
+ };
469
+ }
470
+ }
471
+ async updateClineOrMSRooSettings(settingPath, serverName, installConfig, // Use the processed installConfig
472
+ clientName) {
473
+ // Read the Cline/MSRoo settings file
474
+ const settings = await readJsonFile(settingPath, true);
475
+ // Initialize mcpServers section if it doesn't exist
476
+ if (!settings.mcpServers) {
477
+ settings.mcpServers = {};
478
+ }
479
+ // Special handling for Windows when command is npx for Cline and MSROO clients
480
+ // Use a copy to avoid modifying the passed installConfig directly if needed elsewhere
481
+ const serverConfigForClient = { ...installConfig };
482
+ if (process.platform === 'win32' &&
483
+ serverConfigForClient.command === 'npx' &&
484
+ (clientName === 'Cline' || clientName === 'MSRooCode' || clientName === 'MSROO')) {
485
+ // Update command to cmd
486
+ serverConfigForClient.command = 'cmd';
487
+ // Add /c and npx at the beginning of args
488
+ serverConfigForClient.args = ['/c', 'npx', ...serverConfigForClient.args];
489
+ // Add APPDATA environment variable pointing to npm directory
490
+ if (!serverConfigForClient.env) {
491
+ serverConfigForClient.env = {};
492
+ }
493
+ // Dynamically get npm path and set APPDATA to it
494
+ const npmPath = await this.getNpmPath();
495
+ serverConfigForClient.env['APPDATA'] = npmPath;
496
+ Logger.debug(`Windows npx fix: command=${serverConfigForClient.command}, args=${serverConfigForClient.args.join(' ')}, env=${JSON.stringify(serverConfigForClient.env)}`);
497
+ }
498
+ // Convert backslashes to forward slashes in args paths
499
+ if (serverConfigForClient.args) {
500
+ serverConfigForClient.args = serverConfigForClient.args.map((arg) => typeof arg === 'string' ? arg.replace(/\\/g, '/') : arg);
501
+ }
502
+ // Add or update the server configuration
503
+ settings.mcpServers[serverName] = {
504
+ command: serverConfigForClient.command,
505
+ args: serverConfigForClient.args,
506
+ env: serverConfigForClient.env,
507
+ autoApprove: [],
508
+ disabled: false,
509
+ alwaysAllow: []
510
+ };
511
+ Logger.debug(`Updating ${settingPath} for ${serverName}: ${JSON.stringify(settings.mcpServers[serverName])}`);
512
+ // Write the updated settings back to the file
513
+ await writeJsonFile(settingPath, settings);
514
+ }
515
+ async updateGithubCopilotSettings(settingPath, serverName, installConfig // Use the processed installConfig
516
+ ) {
517
+ // Read the VS Code settings.json file
518
+ const settings = await readJsonFile(settingPath, true);
519
+ // Initialize the mcp section if it doesn't exist
520
+ if (!settings.mcp) {
521
+ settings.mcp = {
522
+ servers: {},
523
+ inputs: []
524
+ };
525
+ }
526
+ if (!settings.mcp.servers) {
527
+ settings.mcp.servers = {};
528
+ }
529
+ // Use a copy to avoid modifying the passed installConfig directly
530
+ const serverConfigForClient = { ...installConfig };
531
+ // Convert backslashes to forward slashes in args paths
532
+ if (serverConfigForClient.args) {
533
+ serverConfigForClient.args = serverConfigForClient.args.map((arg) => typeof arg === 'string' ? arg.replace(/\\/g, '/') : arg);
534
+ }
535
+ // Add or update the server configuration
536
+ settings.mcp.servers[serverName] = {
537
+ command: serverConfigForClient.command,
538
+ args: serverConfigForClient.args,
539
+ env: serverConfigForClient.env
540
+ };
541
+ Logger.debug(`Updating ${settingPath} for ${serverName}: ${JSON.stringify(settings.mcp.servers[serverName])}`);
542
+ // Write the updated settings back to the file
543
+ await writeJsonFile(settingPath, settings);
544
+ }
545
+ async install(options) {
546
+ const initialStatuses = [];
547
+ // Start installation for each client asynchronously and collect initial statuses
548
+ // Pass options down to installClient
549
+ const installPromises = this.clients.map(async (clientName) => {
550
+ const initialStatus = await this.installClient(clientName, options);
551
+ initialStatuses.push(initialStatus);
552
+ return initialStatus;
553
+ });
554
+ // Wait for all initial statuses (but actual installation continues asynchronously)
555
+ await Promise.all(installPromises);
556
+ // Return initial result showing installations have been initiated
557
+ return {
558
+ success: true,
559
+ message: 'Client installations initiated successfully',
560
+ status: initialStatuses
561
+ };
562
+ }
563
+ }
564
+ //# sourceMappingURL=ClientInstaller.js.map
@@ -0,0 +1,37 @@
1
+ import { RequirementConfig, RequirementStatus } from '../types.js';
2
+ import { BaseInstaller } from './BaseInstaller.js';
3
+ /**
4
+ * Installer implementation for command-line tools
5
+ */
6
+ export declare class CommandInstaller extends BaseInstaller {
7
+ /**
8
+ * Mapping of command names to their package IDs
9
+ * This handles special cases where the command name differs from the package ID
10
+ */
11
+ private commandMappings;
12
+ /**
13
+ * Check if this installer can handle the given requirement type
14
+ * @param requirement The requirement to check
15
+ * @returns True if this installer can handle the requirement
16
+ */
17
+ canHandle(requirement: RequirementConfig): boolean;
18
+ supportCheckUpdates(): boolean;
19
+ /**
20
+ * Get the mapped package ID for a command
21
+ * @param commandName The command name to map
22
+ * @returns The mapped package ID
23
+ */
24
+ private getMappedPackageId;
25
+ /**
26
+ * Check if the command is already installed
27
+ * @param requirement The requirement to check
28
+ * @returns The status of the requirement
29
+ */
30
+ checkInstallation(requirement: RequirementConfig): Promise<RequirementStatus>;
31
+ /**
32
+ * Install the command
33
+ * @param requirement The requirement to install
34
+ * @returns The status of the installation
35
+ */
36
+ install(requirement: RequirementConfig): Promise<RequirementStatus>;
37
+ }