imcp 0.0.1

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 (124) hide show
  1. package/.github/ISSUE_TEMPLATE/JitAccess.yml +28 -0
  2. package/.github/acl/access.yml +20 -0
  3. package/.github/compliance/inventory.yml +5 -0
  4. package/.github/policies/jit.yml +19 -0
  5. package/README.md +137 -0
  6. package/dist/cli/commands/install.d.ts +2 -0
  7. package/dist/cli/commands/install.js +105 -0
  8. package/dist/cli/commands/list.d.ts +2 -0
  9. package/dist/cli/commands/list.js +90 -0
  10. package/dist/cli/commands/pull.d.ts +2 -0
  11. package/dist/cli/commands/pull.js +17 -0
  12. package/dist/cli/commands/serve.d.ts +2 -0
  13. package/dist/cli/commands/serve.js +32 -0
  14. package/dist/cli/commands/start.d.ts +2 -0
  15. package/dist/cli/commands/start.js +32 -0
  16. package/dist/cli/commands/sync.d.ts +2 -0
  17. package/dist/cli/commands/sync.js +17 -0
  18. package/dist/cli/commands/uninstall.d.ts +2 -0
  19. package/dist/cli/commands/uninstall.js +39 -0
  20. package/dist/cli/index.d.ts +2 -0
  21. package/dist/cli/index.js +114 -0
  22. package/dist/core/ConfigurationProvider.d.ts +31 -0
  23. package/dist/core/ConfigurationProvider.js +416 -0
  24. package/dist/core/InstallationService.d.ts +17 -0
  25. package/dist/core/InstallationService.js +144 -0
  26. package/dist/core/MCPManager.d.ts +17 -0
  27. package/dist/core/MCPManager.js +98 -0
  28. package/dist/core/RequirementService.d.ts +45 -0
  29. package/dist/core/RequirementService.js +123 -0
  30. package/dist/core/constants.d.ts +29 -0
  31. package/dist/core/constants.js +55 -0
  32. package/dist/core/installers/BaseInstaller.d.ts +73 -0
  33. package/dist/core/installers/BaseInstaller.js +247 -0
  34. package/dist/core/installers/ClientInstaller.d.ts +17 -0
  35. package/dist/core/installers/ClientInstaller.js +307 -0
  36. package/dist/core/installers/CommandInstaller.d.ts +36 -0
  37. package/dist/core/installers/CommandInstaller.js +170 -0
  38. package/dist/core/installers/GeneralInstaller.d.ts +32 -0
  39. package/dist/core/installers/GeneralInstaller.js +87 -0
  40. package/dist/core/installers/InstallerFactory.d.ts +52 -0
  41. package/dist/core/installers/InstallerFactory.js +95 -0
  42. package/dist/core/installers/NpmInstaller.d.ts +25 -0
  43. package/dist/core/installers/NpmInstaller.js +123 -0
  44. package/dist/core/installers/PipInstaller.d.ts +25 -0
  45. package/dist/core/installers/PipInstaller.js +114 -0
  46. package/dist/core/installers/RequirementInstaller.d.ts +32 -0
  47. package/dist/core/installers/RequirementInstaller.js +3 -0
  48. package/dist/core/installers/index.d.ts +6 -0
  49. package/dist/core/installers/index.js +7 -0
  50. package/dist/core/types.d.ts +152 -0
  51. package/dist/core/types.js +16 -0
  52. package/dist/index.d.ts +11 -0
  53. package/dist/index.js +19 -0
  54. package/dist/services/InstallRequestValidator.d.ts +21 -0
  55. package/dist/services/InstallRequestValidator.js +99 -0
  56. package/dist/services/ServerService.d.ts +47 -0
  57. package/dist/services/ServerService.js +145 -0
  58. package/dist/utils/UpdateCheckTracker.d.ts +39 -0
  59. package/dist/utils/UpdateCheckTracker.js +80 -0
  60. package/dist/utils/clientUtils.d.ts +29 -0
  61. package/dist/utils/clientUtils.js +105 -0
  62. package/dist/utils/feedUtils.d.ts +5 -0
  63. package/dist/utils/feedUtils.js +29 -0
  64. package/dist/utils/githubAuth.d.ts +1 -0
  65. package/dist/utils/githubAuth.js +123 -0
  66. package/dist/utils/logger.d.ts +14 -0
  67. package/dist/utils/logger.js +90 -0
  68. package/dist/utils/osUtils.d.ts +16 -0
  69. package/dist/utils/osUtils.js +235 -0
  70. package/dist/web/public/css/modal.css +250 -0
  71. package/dist/web/public/css/notifications.css +70 -0
  72. package/dist/web/public/index.html +157 -0
  73. package/dist/web/public/js/api.js +213 -0
  74. package/dist/web/public/js/modal.js +572 -0
  75. package/dist/web/public/js/notifications.js +99 -0
  76. package/dist/web/public/js/serverCategoryDetails.js +210 -0
  77. package/dist/web/public/js/serverCategoryList.js +82 -0
  78. package/dist/web/public/modal.html +61 -0
  79. package/dist/web/public/styles.css +155 -0
  80. package/dist/web/server.d.ts +5 -0
  81. package/dist/web/server.js +150 -0
  82. package/package.json +53 -0
  83. package/src/cli/commands/install.ts +140 -0
  84. package/src/cli/commands/list.ts +112 -0
  85. package/src/cli/commands/pull.ts +16 -0
  86. package/src/cli/commands/serve.ts +37 -0
  87. package/src/cli/commands/uninstall.ts +54 -0
  88. package/src/cli/index.ts +127 -0
  89. package/src/core/ConfigurationProvider.ts +489 -0
  90. package/src/core/InstallationService.ts +173 -0
  91. package/src/core/MCPManager.ts +134 -0
  92. package/src/core/RequirementService.ts +147 -0
  93. package/src/core/constants.ts +61 -0
  94. package/src/core/installers/BaseInstaller.ts +292 -0
  95. package/src/core/installers/ClientInstaller.ts +423 -0
  96. package/src/core/installers/CommandInstaller.ts +185 -0
  97. package/src/core/installers/GeneralInstaller.ts +89 -0
  98. package/src/core/installers/InstallerFactory.ts +109 -0
  99. package/src/core/installers/NpmInstaller.ts +128 -0
  100. package/src/core/installers/PipInstaller.ts +121 -0
  101. package/src/core/installers/RequirementInstaller.ts +38 -0
  102. package/src/core/installers/index.ts +9 -0
  103. package/src/core/types.ts +163 -0
  104. package/src/index.ts +44 -0
  105. package/src/services/InstallRequestValidator.ts +112 -0
  106. package/src/services/ServerService.ts +181 -0
  107. package/src/utils/UpdateCheckTracker.ts +86 -0
  108. package/src/utils/clientUtils.ts +112 -0
  109. package/src/utils/feedUtils.ts +31 -0
  110. package/src/utils/githubAuth.ts +142 -0
  111. package/src/utils/logger.ts +101 -0
  112. package/src/utils/osUtils.ts +250 -0
  113. package/src/web/public/css/modal.css +250 -0
  114. package/src/web/public/css/notifications.css +70 -0
  115. package/src/web/public/index.html +157 -0
  116. package/src/web/public/js/api.js +213 -0
  117. package/src/web/public/js/modal.js +572 -0
  118. package/src/web/public/js/notifications.js +99 -0
  119. package/src/web/public/js/serverCategoryDetails.js +210 -0
  120. package/src/web/public/js/serverCategoryList.js +82 -0
  121. package/src/web/public/modal.html +61 -0
  122. package/src/web/public/styles.css +155 -0
  123. package/src/web/server.ts +195 -0
  124. package/tsconfig.json +18 -0
@@ -0,0 +1,423 @@
1
+ import {
2
+ ServerOperationResult,
3
+ OperationStatus,
4
+ MCPServerStatus,
5
+ RequirementStatus,
6
+ ServerInstallOptions,
7
+ FeedConfiguration,
8
+ McpConfig
9
+ } from '../types.js';
10
+ import { ConfigurationProvider } from '../ConfigurationProvider.js';
11
+ import { SUPPORTED_CLIENTS } from '../constants.js';
12
+ import { resolveNpmModulePath, readJsonFile, writeJsonFile } from '../../utils/clientUtils.js';
13
+ import { exec } from 'child_process';
14
+ import { promisify } from 'util';
15
+
16
+ export class ClientInstaller {
17
+ private configProvider: ConfigurationProvider;
18
+ private operationStatuses: Map<string, OperationStatus>;
19
+
20
+ constructor(
21
+ private categoryName: string,
22
+ private serverName: string,
23
+ private clients: string[]
24
+ ) {
25
+ this.configProvider = ConfigurationProvider.getInstance();
26
+ this.operationStatuses = new Map();
27
+ }
28
+
29
+ private generateOperationId(): string {
30
+ return `install-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
31
+ }
32
+
33
+ private async getNpmPath(): Promise<string> {
34
+ const execAsync = promisify(exec);
35
+ try {
36
+ // Execute the get-command npm command to find the npm path
37
+ const { stdout } = await execAsync('powershell -Command "get-command npm | Select-Object -ExpandProperty Source"');
38
+
39
+ // Extract the directory from the full path (removing npm.cmd)
40
+ const npmPath = stdout.trim().replace(/\\npm\.cmd$/, '');
41
+ return npmPath;
42
+ } catch (error) {
43
+ console.error('Error getting npm path:', error);
44
+ // Return a default path if the command fails
45
+ return 'C:\\Program Files\\nodejs';
46
+ }
47
+ }
48
+
49
+ private async installClient(clientName: string, env?: Record<string, string>): Promise<OperationStatus> {
50
+ // Check if client is supported
51
+ if (!SUPPORTED_CLIENTS[clientName]) {
52
+ return {
53
+ status: 'failed',
54
+ type: 'install',
55
+ target: 'server',
56
+ message: `Unsupported client: ${clientName}`,
57
+ operationId: this.generateOperationId()
58
+ };
59
+ }
60
+
61
+ // Create initial operation status
62
+ const operationId = this.generateOperationId();
63
+ const initialStatus: OperationStatus = {
64
+ status: 'pending',
65
+ type: 'install',
66
+ target: 'server',
67
+ message: `Initializing installation for client: ${clientName}`,
68
+ operationId: operationId
69
+ };
70
+
71
+ // Update server status with initial client installation status
72
+ await this.configProvider.updateServerOperationStatus(
73
+ this.categoryName,
74
+ this.serverName,
75
+ clientName,
76
+ initialStatus
77
+ );
78
+
79
+ // Start the asynchronous installation process without awaiting it
80
+ this.processInstallation(clientName, operationId, env);
81
+
82
+ // Return the initial status immediately
83
+ return initialStatus;
84
+ }
85
+
86
+ private async processInstallation(clientName: string, operationId: string, env?: Record<string, string>): Promise<void> {
87
+ try {
88
+ // Check requirements before installation
89
+ let requirementsReady = await this.configProvider.isRequirementsReady(this.categoryName, this.serverName);
90
+
91
+ // If requirements are not ready, periodically check with timeout
92
+ if (!requirementsReady) {
93
+ const pendingStatus: OperationStatus = {
94
+ status: 'pending',
95
+ type: 'install',
96
+ target: 'server',
97
+ message: `Waiting for requirements to be ready for client: ${clientName}`,
98
+ operationId: operationId
99
+ };
100
+
101
+ // Update status to pending with reference to configProvider
102
+ await this.configProvider.updateServerOperationStatus(
103
+ this.categoryName,
104
+ this.serverName,
105
+ clientName,
106
+ pendingStatus
107
+ );
108
+
109
+ // Set up periodic checking with timeout
110
+ const startTime = Date.now();
111
+ const timeoutMs = 5 * 60 * 1000; // 5 minutes in milliseconds
112
+ const intervalMs = 5 * 1000; // 5 seconds in milliseconds
113
+
114
+ while (!requirementsReady && (Date.now() - startTime) < timeoutMs) {
115
+ // Wait for the interval
116
+ await new Promise(resolve => setTimeout(resolve, intervalMs));
117
+
118
+ // Check again
119
+ requirementsReady = await this.configProvider.isRequirementsReady(this.categoryName, this.serverName);
120
+ }
121
+
122
+ // If still not ready after timeout, update status as failed and exit
123
+ if (!requirementsReady) {
124
+ const failedStatus: OperationStatus = {
125
+ status: 'failed',
126
+ type: 'install',
127
+ target: 'server',
128
+ message: `Timed out waiting for requirements to be ready for client: ${clientName} after 5 minutes`,
129
+ operationId: operationId
130
+ };
131
+
132
+ await this.configProvider.updateServerOperationStatus(
133
+ this.categoryName,
134
+ this.serverName,
135
+ clientName,
136
+ failedStatus
137
+ );
138
+
139
+ return; // Exit the installation process
140
+ }
141
+ }
142
+
143
+ // If we've reached here, requirements are ready - update status to in-progress
144
+ const inProgressStatus: OperationStatus = {
145
+ status: 'in-progress',
146
+ type: 'install',
147
+ target: 'server',
148
+ message: `Installing client: ${clientName}`,
149
+ operationId: operationId
150
+ };
151
+
152
+ await this.configProvider.updateServerOperationStatus(
153
+ this.categoryName,
154
+ this.serverName,
155
+ clientName,
156
+ inProgressStatus
157
+ );
158
+
159
+ // Get feed configuration for the server
160
+ const feedConfiguration = await this.configProvider.getFeedConfiguration(this.categoryName);
161
+ if (!feedConfiguration) {
162
+ const errorStatus: OperationStatus = {
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(
170
+ this.categoryName,
171
+ this.serverName,
172
+ clientName,
173
+ errorStatus
174
+ );
175
+ return;
176
+ }
177
+
178
+ // Find the server config in the feed configuration
179
+ const serverConfig = feedConfiguration.mcpServers.find(s => s.name === this.serverName);
180
+ if (!serverConfig) {
181
+ const errorStatus: OperationStatus = {
182
+ status: 'failed',
183
+ type: 'install',
184
+ target: 'server',
185
+ message: `Server ${this.serverName} not found in feed configuration`,
186
+ operationId: operationId
187
+ };
188
+ await this.configProvider.updateServerOperationStatus(
189
+ this.categoryName,
190
+ this.serverName,
191
+ clientName,
192
+ errorStatus
193
+ );
194
+ return;
195
+ }
196
+
197
+ try {
198
+ // Install client-specific configuration
199
+ const result = await this.installClientConfig(clientName, env || {}, serverConfig, feedConfiguration);
200
+
201
+ const finalStatus: OperationStatus = {
202
+ status: result.success ? 'completed' : 'failed',
203
+ type: 'install',
204
+ target: 'server',
205
+ message: result.message || `Installation for client ${clientName}: ${result.success ? 'successful' : 'failed'}`,
206
+ operationId: operationId,
207
+ error: result.success ? undefined : result.message
208
+ };
209
+
210
+ await this.configProvider.updateServerOperationStatus(
211
+ this.categoryName,
212
+ this.serverName,
213
+ clientName,
214
+ finalStatus
215
+ );
216
+
217
+ } catch (error) {
218
+ const errorStatus: OperationStatus = {
219
+ status: 'failed',
220
+ type: 'install',
221
+ target: 'server',
222
+ message: `Failed to install client: ${clientName}. Error: ${error instanceof Error ? error.message : String(error)}`,
223
+ operationId: operationId,
224
+ error: error instanceof Error ? error.message : String(error)
225
+ };
226
+
227
+ await this.configProvider.updateServerOperationStatus(
228
+ this.categoryName,
229
+ this.serverName,
230
+ clientName,
231
+ errorStatus
232
+ );
233
+ }
234
+ } catch (error) {
235
+ const errorStatus: OperationStatus = {
236
+ status: 'failed',
237
+ type: 'install',
238
+ target: 'server',
239
+ message: `Unexpected error in installation process for client: ${clientName}. Error: ${error instanceof Error ? error.message : String(error)}`,
240
+ operationId: operationId,
241
+ error: error instanceof Error ? error.message : String(error)
242
+ };
243
+
244
+ await this.configProvider.updateServerOperationStatus(
245
+ this.categoryName,
246
+ this.serverName,
247
+ clientName,
248
+ errorStatus
249
+ );
250
+ }
251
+ }
252
+
253
+ private async installClientConfig(
254
+ clientName: string,
255
+ env: Record<string, string>,
256
+ serverConfig: McpConfig,
257
+ feedConfig: FeedConfiguration
258
+ ): Promise<{ success: boolean; message: string }> {
259
+ try {
260
+ if (!SUPPORTED_CLIENTS[clientName]) {
261
+ return { success: false, message: `Unsupported client: ${clientName}` };
262
+ }
263
+
264
+ const clientSettings = SUPPORTED_CLIENTS[clientName];
265
+
266
+ // Determine which setting path to use based on VS Code type (regular or insiders)
267
+ const settingPath = process.env.CODE_INSIDERS
268
+ ? clientSettings.codeInsiderSettingPath
269
+ : clientSettings.codeSettingPath;
270
+
271
+ if (!settingPath) {
272
+ return { success: false, message: `No settings path found for client: ${clientName}` };
273
+ }
274
+
275
+ // Clone the installation configuration to make modifications
276
+ const installConfig = JSON.parse(JSON.stringify(serverConfig.installation));
277
+
278
+ // Replace template variables in args
279
+ installConfig.args = installConfig.args.map((arg: string) =>
280
+ resolveNpmModulePath(arg));
281
+
282
+ // Add environment variables from options
283
+ installConfig.env = {};
284
+ if (serverConfig.installation.env) {
285
+ // Add default env variables from config
286
+ for (const [key, config] of Object.entries(serverConfig.installation.env)) {
287
+ const envConfig = config as any; // Type assertion for dynamic access
288
+ if (envConfig.Default) {
289
+ installConfig.env[key] = envConfig.Default;
290
+ }
291
+ }
292
+ }
293
+
294
+ // Override with provided env variables
295
+ if (env) {
296
+ Object.assign(installConfig.env, env);
297
+ }
298
+
299
+ // Update client-specific settings
300
+ if (clientName === 'MSRooCode' || clientName === 'Cline') {
301
+ await this.updateClineOrMSRooSettings(settingPath, this.serverName, installConfig, clientName);
302
+ } else if (clientName === 'GithubCopilot') {
303
+ await this.updateGithubCopilotSettings(settingPath, this.serverName, installConfig);
304
+ } else {
305
+ return {
306
+ success: false,
307
+ message: `Client ${clientName} is supported but no implementation exists for updating its settings`
308
+ };
309
+ }
310
+
311
+ return {
312
+ success: true,
313
+ message: `Successfully installed ${this.serverName} for client: ${clientName}`
314
+ };
315
+ } catch (error) {
316
+ return {
317
+ success: false,
318
+ message: `Error installing client ${clientName}: ${error instanceof Error ? error.message : String(error)}`
319
+ };
320
+ }
321
+ }
322
+
323
+ private async updateClineOrMSRooSettings(
324
+ settingPath: string,
325
+ serverName: string,
326
+ installConfig: any,
327
+ clientName: string
328
+ ): Promise<void> {
329
+ // Read the Cline/MSRoo settings file
330
+ const settings = await readJsonFile(settingPath, true);
331
+
332
+ // Initialize mcpServers section if it doesn't exist
333
+ if (!settings.mcpServers) {
334
+ settings.mcpServers = {};
335
+ }
336
+
337
+ // Special handling for Windows when command is npx for Cline and MSROO clients
338
+ const serverConfig = { ...installConfig };
339
+ if (process.platform === 'win32' &&
340
+ serverConfig.command === 'npx' &&
341
+ (clientName === 'Cline' || clientName === 'MSRooCode' || clientName === 'MSROO')) {
342
+ // Update command to cmd
343
+ serverConfig.command = 'cmd';
344
+
345
+ // Add /c and npx at the beginning of args
346
+ serverConfig.args = ['/c', 'npx', ...serverConfig.args];
347
+
348
+ // Add APPDATA environment variable pointing to npm directory
349
+ if (!serverConfig.env) {
350
+ serverConfig.env = {};
351
+ }
352
+
353
+ // Dynamically get npm path and set APPDATA to it
354
+ const npmPath = await this.getNpmPath();
355
+ serverConfig.env['APPDATA'] = npmPath;
356
+ }
357
+
358
+ // Add or update the server configuration
359
+ settings.mcpServers[serverName] = {
360
+ command: serverConfig.command,
361
+ args: serverConfig.args,
362
+ env: serverConfig.env,
363
+ autoApprove: [],
364
+ disabled: false,
365
+ alwaysAllow: []
366
+ };
367
+
368
+ // Write the updated settings back to the file
369
+ await writeJsonFile(settingPath, settings);
370
+ }
371
+
372
+ private async updateGithubCopilotSettings(
373
+ settingPath: string,
374
+ serverName: string,
375
+ installConfig: any
376
+ ): Promise<void> {
377
+ // Read the VS Code settings.json file
378
+ const settings = await readJsonFile(settingPath, true);
379
+
380
+ // Initialize the mcp section if it doesn't exist
381
+ if (!settings.mcp) {
382
+ settings.mcp = {
383
+ servers: {},
384
+ inputs: []
385
+ };
386
+ }
387
+
388
+ if (!settings.mcp.servers) {
389
+ settings.mcp.servers = {};
390
+ }
391
+
392
+ // Add or update the server configuration
393
+ settings.mcp.servers[serverName] = {
394
+ command: installConfig.command,
395
+ args: installConfig.args,
396
+ env: installConfig.env
397
+ };
398
+
399
+ // Write the updated settings back to the file
400
+ await writeJsonFile(settingPath, settings);
401
+ }
402
+
403
+ async install(options: ServerInstallOptions): Promise<ServerOperationResult> {
404
+ const initialStatuses: OperationStatus[] = [];
405
+
406
+ // Start installation for each client asynchronously and collect initial statuses
407
+ const installPromises = this.clients.map(async (clientName) => {
408
+ const initialStatus = await this.installClient(clientName, options.env || {});
409
+ initialStatuses.push(initialStatus);
410
+ return initialStatus;
411
+ });
412
+
413
+ // Wait for all initial statuses (but actual installation continues asynchronously)
414
+ await Promise.all(installPromises);
415
+
416
+ // Return initial result showing installations have been initiated
417
+ return {
418
+ success: true,
419
+ message: 'Client installations initiated successfully',
420
+ status: initialStatuses
421
+ };
422
+ }
423
+ }
@@ -0,0 +1,185 @@
1
+ import { RequirementConfig, RequirementStatus, OSType } from '../types.js';
2
+ import { BaseInstaller } from './BaseInstaller.js';
3
+ import { getOSType, refreshPathEnv } from '../../utils/osUtils.js';
4
+ import { Logger } from '../../utils/logger.js';
5
+
6
+ /**
7
+ * Mapping of command names to their package IDs on different platforms
8
+ */
9
+ interface CommandMapping {
10
+ windows: string;
11
+ macos: string;
12
+ }
13
+
14
+ /**
15
+ * Installer implementation for command-line tools
16
+ */
17
+ export class CommandInstaller extends BaseInstaller {
18
+ /**
19
+ * Mapping of command names to their package IDs
20
+ * This handles special cases where the command name differs from the package ID
21
+ */
22
+ private commandMappings: Record<string, CommandMapping> = {
23
+ 'uv': { windows: 'astral-sh.uv', macos: 'uv' }
24
+ // Add more mappings as needed
25
+ };
26
+
27
+ /**
28
+ * Check if this installer can handle the given requirement type
29
+ * @param requirement The requirement to check
30
+ * @returns True if this installer can handle the requirement
31
+ */
32
+ canHandle(requirement: RequirementConfig): boolean {
33
+ return requirement.type === 'command';
34
+ }
35
+
36
+ /**
37
+ * Get the mapped package ID for a command
38
+ * @param commandName The command name to map
39
+ * @returns The mapped package ID
40
+ */
41
+ private getMappedPackageId(commandName: string): string {
42
+ const osType = getOSType();
43
+ const mapping = this.commandMappings[commandName];
44
+
45
+ if (mapping) {
46
+ return osType === OSType.Windows ? mapping.windows : mapping.macos;
47
+ }
48
+
49
+ // If no mapping exists, use the command name itself
50
+ return commandName;
51
+ }
52
+
53
+ /**
54
+ * Check if the command is already installed
55
+ * @param requirement The requirement to check
56
+ * @returns The status of the requirement
57
+ */
58
+ async checkInstallation(requirement: RequirementConfig): Promise<RequirementStatus> {
59
+ try {
60
+ await refreshPathEnv();
61
+ const commandName = requirement.alias || requirement.name;
62
+ const osType = getOSType();
63
+ let commandResult;
64
+
65
+ if (osType === OSType.Windows) {
66
+ // Check if command exists on Windows
67
+ try {
68
+ commandResult = await this.execPromise(`where ${commandName} 2>nul`);
69
+ } catch (error) {
70
+ Logger.debug(`Error checking command existence: ${error}`);
71
+ // On Windows, 'where' command returns non-zero exit code if the command is not found
72
+ // We'll handle this as "command not found" rather than an error
73
+ commandResult = { stdout: '', stderr: '' };
74
+ }
75
+ } else {
76
+ // Check if command exists on macOS/Linux
77
+ try {
78
+ commandResult = await this.execPromise(`which ${commandName} 2>/dev/null`);
79
+ } catch (error) {
80
+ Logger.debug(`Error checking command existence: ${error}`);
81
+ // Similarly handle command not found on Unix systems
82
+ commandResult = { stdout: '', stderr: '' };
83
+ }
84
+ }
85
+
86
+ // If the command exists, it will return a path or multiple paths
87
+ const installed = commandResult.stdout.trim().length > 0;
88
+
89
+ // Try to get version information if available
90
+ let version: string | undefined;
91
+ if (installed) {
92
+ try {
93
+ const versionResult = await this.execPromise(`${commandName} --version`);
94
+ if (versionResult.stdout) {
95
+ // Extract version information - this is a simple approach that might need refinement
96
+ const versionMatch = versionResult.stdout.match(/\d+\.\d+(\.\d+)?/);
97
+ version = versionMatch ? versionMatch[0] : undefined;
98
+ }
99
+ } catch (error) {
100
+ Logger.debug(`Error checking command version: ${error}`);
101
+ // Ignore errors from version check, consider it installed anyway
102
+ }
103
+ }
104
+
105
+ return {
106
+ name: requirement.name,
107
+ type: 'command',
108
+ installed,
109
+ version,
110
+ inProgress: false
111
+ };
112
+ } catch (error) {
113
+ Logger.error(`Error checking installation: ${error}`);
114
+ return {
115
+ name: requirement.name,
116
+ type: 'command',
117
+ installed: false,
118
+ error: error instanceof Error ? error.message : String(error),
119
+ inProgress: false
120
+ };
121
+ }
122
+ }
123
+
124
+ /**
125
+ * Install the command
126
+ * @param requirement The requirement to install
127
+ * @returns The status of the installation
128
+ */
129
+ async install(requirement: RequirementConfig): Promise<RequirementStatus> {
130
+ try {
131
+ const status = await this.checkInstallation(requirement);
132
+ if (status.installed) {
133
+ return status;
134
+ }
135
+
136
+ const packageId = this.getMappedPackageId(requirement.name);
137
+ const osType = getOSType();
138
+ let installCommand: string;
139
+
140
+ if (osType === OSType.Windows) {
141
+ // Windows installation using winget
142
+ installCommand = `winget install --id ${packageId}`;
143
+ if (requirement.version && requirement.version !== 'latest') {
144
+ installCommand += ` --version ${requirement.version}`;
145
+ }
146
+ } else if (osType === OSType.MacOS) {
147
+ // macOS installation using Homebrew
148
+ installCommand = `brew install ${packageId}`;
149
+ if (requirement.version && requirement.version !== 'latest') {
150
+ installCommand += `@${requirement.version}`;
151
+ }
152
+ } else {
153
+ throw new Error(`Unsupported operating system for installing ${requirement.name}`);
154
+ }
155
+
156
+ // Execute the installation command
157
+ const { stderr } = await this.execPromise(installCommand);
158
+ if (stderr && stderr.toLowerCase().includes('error')) {
159
+ throw new Error(stderr);
160
+ }
161
+
162
+ // Check if installation was successful
163
+ const updatedStatus = await this.checkInstallation(requirement);
164
+ if (!updatedStatus.installed) {
165
+ throw new Error(`Failed to install ${requirement.name}`);
166
+ }
167
+
168
+ return {
169
+ name: requirement.name,
170
+ type: 'command',
171
+ installed: true,
172
+ version: updatedStatus.version || requirement.version,
173
+ inProgress: false
174
+ };
175
+ } catch (error) {
176
+ return {
177
+ name: requirement.name,
178
+ type: 'command',
179
+ installed: false,
180
+ error: error instanceof Error ? error.message : String(error),
181
+ inProgress: false
182
+ };
183
+ }
184
+ }
185
+ }
@@ -0,0 +1,89 @@
1
+ import { RequirementConfig, RequirementStatus } from '../types.js';
2
+ import { BaseInstaller } from './BaseInstaller.js';
3
+
4
+ /**
5
+ * Installer implementation for general requirements (type 'other')
6
+ * This installer handles requirements that don't fit into specific package manager categories
7
+ */
8
+ export class GeneralInstaller extends BaseInstaller {
9
+ /**
10
+ * Check if this installer can handle the given requirement type
11
+ * @param requirement The requirement to check
12
+ * @returns True if this installer can handle the requirement
13
+ */
14
+ canHandle(requirement: RequirementConfig): boolean {
15
+ return requirement.type === 'other';
16
+ }
17
+
18
+ /**
19
+ * Check if the requirement is already installed
20
+ * For general installers, we can't easily check if something is installed
21
+ * without specific knowledge of the requirement, so we always return false
22
+ *
23
+ * @param requirement The requirement to check
24
+ * @returns The status of the requirement
25
+ */
26
+ async checkInstallation(requirement: RequirementConfig): Promise<RequirementStatus> {
27
+ // For general installers, we can't easily check if something is installed
28
+ // So we'll always return not installed, and the actual installation will check
29
+ return {
30
+ name: requirement.name,
31
+ type: 'other',
32
+ installed: false,
33
+ inProgress: false
34
+ };
35
+ }
36
+
37
+ /**
38
+ * Install the general requirement
39
+ * For type 'other', this doesn't actually install anything, but downloads
40
+ * or locates the asset and returns the path for the caller to use
41
+ *
42
+ * @param requirement The requirement to install
43
+ * @returns The status of the installation, including the install path in updateInfo
44
+ */
45
+ async install(requirement: RequirementConfig): Promise<RequirementStatus> {
46
+ try {
47
+ // For type 'other', a registry must be specified
48
+ if (!requirement.registry) {
49
+ throw new Error('Registry must be specified for requirement type "other"');
50
+ }
51
+
52
+ let installPath: string;
53
+
54
+ if (requirement.registry.githubRelease) {
55
+ const result = await this.handleGitHubRelease(requirement, requirement.registry.githubRelease);
56
+ installPath = result.resolvedPath;
57
+ } else if (requirement.registry.artifacts) {
58
+ installPath = await this.handleArtifactsRegistry(requirement, requirement.registry.artifacts);
59
+ } else if (requirement.registry.local) {
60
+ installPath = await this.handleLocalRegistry(requirement, requirement.registry.local);
61
+ } else {
62
+ throw new Error('Invalid registry configuration');
63
+ }
64
+
65
+ // For general installer, we just return the path to the downloaded/located file
66
+ // The actual installation mechanism would depend on the specific requirement
67
+ return {
68
+ name: requirement.name,
69
+ type: 'other',
70
+ installed: true,
71
+ version: requirement.version,
72
+ inProgress: false,
73
+ // Store installation path in a way that it can be retrieved later if needed
74
+ updateInfo: {
75
+ available: false,
76
+ installPath
77
+ }
78
+ };
79
+ } catch (error) {
80
+ return {
81
+ name: requirement.name,
82
+ type: 'other',
83
+ installed: false,
84
+ error: error instanceof Error ? error.message : String(error),
85
+ inProgress: false
86
+ };
87
+ }
88
+ }
89
+ }