imcp 0.1.5 → 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 (186) 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/.github/workflows/build.yml +28 -0
  6. package/.roo/rules-code/rules.md +88 -0
  7. package/docs/ONBOARDING_PAGE_DESIGN.md +260 -0
  8. package/docs/Telemetry.md +136 -0
  9. package/memory-bank/activeContext.md +26 -0
  10. package/memory-bank/decisionLog.md +91 -0
  11. package/memory-bank/productContext.md +41 -0
  12. package/memory-bank/progress.md +35 -0
  13. package/memory-bank/systemPatterns.md +10 -0
  14. package/package.json +1 -5
  15. package/src/cli/commands/install.ts +139 -0
  16. package/src/cli/commands/list.ts +113 -0
  17. package/src/cli/commands/pull.ts +16 -0
  18. package/src/cli/commands/serve.ts +39 -0
  19. package/src/cli/commands/uninstall.ts +64 -0
  20. package/src/cli/index.ts +82 -0
  21. package/src/core/installers/clients/BaseClientInstaller.ts +341 -0
  22. package/src/core/installers/clients/ClientInstaller.ts +222 -0
  23. package/src/core/installers/clients/ClientInstallerFactory.ts +43 -0
  24. package/src/core/installers/clients/ClineInstaller.ts +35 -0
  25. package/src/core/installers/clients/ExtensionInstaller.ts +165 -0
  26. package/src/core/installers/clients/GithubCopilotInstaller.ts +79 -0
  27. package/src/core/installers/clients/MSRooCodeInstaller.ts +32 -0
  28. package/src/core/installers/index.ts +11 -0
  29. package/src/core/installers/requirements/BaseInstaller.ts +85 -0
  30. package/src/core/installers/requirements/CommandInstaller.ts +231 -0
  31. package/src/core/installers/requirements/GeneralInstaller.ts +133 -0
  32. package/src/core/installers/requirements/InstallerFactory.ts +114 -0
  33. package/src/core/installers/requirements/NpmInstaller.ts +271 -0
  34. package/src/core/installers/requirements/NugetInstaller.ts +203 -0
  35. package/src/core/installers/requirements/PipInstaller.ts +207 -0
  36. package/src/core/installers/requirements/RequirementInstaller.ts +42 -0
  37. package/src/core/loaders/ConfigurationLoader.ts +298 -0
  38. package/src/core/loaders/ConfigurationProvider.ts +462 -0
  39. package/src/core/loaders/InstallOperationManager.ts +367 -0
  40. package/src/core/loaders/ServerSchemaLoader.ts +117 -0
  41. package/src/core/loaders/ServerSchemaProvider.ts +99 -0
  42. package/src/core/loaders/SystemSettingsManager.ts +278 -0
  43. package/src/core/metadatas/constants.ts +122 -0
  44. package/src/core/metadatas/recordingConstants.ts +65 -0
  45. package/src/core/metadatas/types.ts +202 -0
  46. package/src/core/onboard/FeedOnboardService.ts +501 -0
  47. package/src/core/onboard/OnboardProcessor.ts +356 -0
  48. package/src/core/onboard/OnboardStatus.ts +60 -0
  49. package/src/core/onboard/OnboardStatusManager.ts +416 -0
  50. package/src/core/validators/FeedValidator.ts +135 -0
  51. package/src/core/validators/IServerValidator.ts +21 -0
  52. package/src/core/validators/SSEServerValidator.ts +43 -0
  53. package/src/core/validators/ServerValidatorFactory.ts +51 -0
  54. package/src/core/validators/StdioServerValidator.ts +313 -0
  55. package/src/index.ts +44 -0
  56. package/src/services/InstallationService.ts +102 -0
  57. package/src/services/MCPManager.ts +249 -0
  58. package/src/services/RequirementService.ts +627 -0
  59. package/src/services/ServerService.ts +161 -0
  60. package/src/services/TelemetryService.ts +59 -0
  61. package/src/utils/UpdateCheckTracker.ts +86 -0
  62. package/src/utils/adoUtils.ts +293 -0
  63. package/src/utils/clientUtils.ts +72 -0
  64. package/src/utils/feedUtils.ts +31 -0
  65. package/src/utils/githubAuth.ts +212 -0
  66. package/src/utils/githubUtils.ts +164 -0
  67. package/src/utils/logger.ts +195 -0
  68. package/src/utils/macroExpressionUtils.ts +104 -0
  69. package/src/utils/osUtils.ts +700 -0
  70. package/src/utils/versionUtils.ts +114 -0
  71. package/src/web/contract/serverContract.ts +74 -0
  72. package/src/web/public/css/detailsWidget.css +235 -0
  73. package/src/web/public/css/modal.css +757 -0
  74. package/src/web/public/css/notifications.css +101 -0
  75. package/src/web/public/css/onboard.css +107 -0
  76. package/src/web/public/css/serverCategoryList.css +120 -0
  77. package/src/web/public/css/serverDetails.css +139 -0
  78. package/src/web/public/index.html +359 -0
  79. package/src/web/public/js/api.js +132 -0
  80. package/src/web/public/js/detailsWidget.js +264 -0
  81. package/src/web/public/js/flights/flights.js +127 -0
  82. package/src/web/public/js/modal/index.js +52 -0
  83. package/src/web/public/js/modal/installModal.js +162 -0
  84. package/src/web/public/js/modal/installation.js +266 -0
  85. package/src/web/public/js/modal/loadingModal.js +182 -0
  86. package/src/web/public/js/modal/modalSetup.js +595 -0
  87. package/src/web/public/js/modal/modalUtils.js +37 -0
  88. package/src/web/public/js/modal/versionUtils.js +20 -0
  89. package/src/web/public/js/modal.js +42 -0
  90. package/src/web/public/js/notifications.js +137 -0
  91. package/src/web/public/js/onboard/formProcessor.js +1037 -0
  92. package/src/web/public/js/onboard/index.js +374 -0
  93. package/src/web/public/js/onboard/publishHandler.js +172 -0
  94. package/src/web/public/js/onboard/state.js +76 -0
  95. package/src/web/public/js/onboard/templates.js +342 -0
  96. package/src/web/public/js/onboard/uiHandlers.js +1076 -0
  97. package/src/web/public/js/onboard/validationHandlers.js +493 -0
  98. package/src/web/public/js/serverCategoryDetails.js +364 -0
  99. package/src/web/public/js/serverCategoryList.js +241 -0
  100. package/src/web/public/js/settings.js +314 -0
  101. package/src/web/public/modal.html +84 -0
  102. package/src/web/public/onboard.html +296 -0
  103. package/src/web/public/settings.html +135 -0
  104. package/src/web/public/styles.css +277 -0
  105. package/src/web/server.ts +478 -0
  106. package/tsconfig.json +18 -0
  107. package/wiki/Installation.md +3 -0
  108. package/wiki/Publish.md +3 -0
  109. package/dist/cli/commands/install.js.map +0 -1
  110. package/dist/cli/commands/list.js.map +0 -1
  111. package/dist/cli/commands/pull.js.map +0 -1
  112. package/dist/cli/commands/serve.js.map +0 -1
  113. package/dist/cli/commands/start.js.map +0 -1
  114. package/dist/cli/commands/sync.js.map +0 -1
  115. package/dist/cli/commands/uninstall.js.map +0 -1
  116. package/dist/cli/index.js.map +0 -1
  117. package/dist/core/ConfigurationLoader.js.map +0 -1
  118. package/dist/core/ConfigurationProvider.js.map +0 -1
  119. package/dist/core/InstallationService.js.map +0 -1
  120. package/dist/core/MCPManager.js.map +0 -1
  121. package/dist/core/RequirementService.js.map +0 -1
  122. package/dist/core/ServerSchemaLoader.js.map +0 -1
  123. package/dist/core/ServerSchemaProvider.js.map +0 -1
  124. package/dist/core/constants.js.map +0 -1
  125. package/dist/core/installers/BaseInstaller.js.map +0 -1
  126. package/dist/core/installers/ClientInstaller.js.map +0 -1
  127. package/dist/core/installers/CommandInstaller.js.map +0 -1
  128. package/dist/core/installers/GeneralInstaller.js.map +0 -1
  129. package/dist/core/installers/InstallerFactory.js.map +0 -1
  130. package/dist/core/installers/NpmInstaller.js.map +0 -1
  131. package/dist/core/installers/PipInstaller.js.map +0 -1
  132. package/dist/core/installers/RequirementInstaller.js.map +0 -1
  133. package/dist/core/installers/clients/BaseClientInstaller.js.map +0 -1
  134. package/dist/core/installers/clients/ClientInstaller.js.map +0 -1
  135. package/dist/core/installers/clients/ClientInstallerFactory.js.map +0 -1
  136. package/dist/core/installers/clients/ClineInstaller.js.map +0 -1
  137. package/dist/core/installers/clients/ExtensionInstaller.js.map +0 -1
  138. package/dist/core/installers/clients/GithubCopilotInstaller.js.map +0 -1
  139. package/dist/core/installers/clients/MSRooCodeInstaller.js.map +0 -1
  140. package/dist/core/installers/index.js.map +0 -1
  141. package/dist/core/installers/requirements/BaseInstaller.js.map +0 -1
  142. package/dist/core/installers/requirements/CommandInstaller.js.map +0 -1
  143. package/dist/core/installers/requirements/GeneralInstaller.js.map +0 -1
  144. package/dist/core/installers/requirements/InstallerFactory.js.map +0 -1
  145. package/dist/core/installers/requirements/NpmInstaller.js.map +0 -1
  146. package/dist/core/installers/requirements/NugetInstaller.js.map +0 -1
  147. package/dist/core/installers/requirements/PipInstaller.js.map +0 -1
  148. package/dist/core/installers/requirements/RequirementInstaller.js.map +0 -1
  149. package/dist/core/loaders/ConfigurationLoader.js.map +0 -1
  150. package/dist/core/loaders/ConfigurationProvider.js.map +0 -1
  151. package/dist/core/loaders/InstallOperationManager.js.map +0 -1
  152. package/dist/core/loaders/ServerSchemaLoader.js.map +0 -1
  153. package/dist/core/loaders/ServerSchemaProvider.js.map +0 -1
  154. package/dist/core/loaders/SystemSettingsManager.js.map +0 -1
  155. package/dist/core/metadatas/constants.js.map +0 -1
  156. package/dist/core/metadatas/recordingConstants.js.map +0 -1
  157. package/dist/core/metadatas/types.js.map +0 -1
  158. package/dist/core/onboard/FeedOnboardService.js.map +0 -1
  159. package/dist/core/onboard/OnboardProcessor.js.map +0 -1
  160. package/dist/core/onboard/OnboardStatus.js.map +0 -1
  161. package/dist/core/onboard/OnboardStatusManager.js.map +0 -1
  162. package/dist/core/types.js.map +0 -1
  163. package/dist/core/validators/FeedValidator.js.map +0 -1
  164. package/dist/core/validators/IServerValidator.js.map +0 -1
  165. package/dist/core/validators/SSEServerValidator.js.map +0 -1
  166. package/dist/core/validators/ServerValidatorFactory.js.map +0 -1
  167. package/dist/core/validators/StdioServerValidator.js.map +0 -1
  168. package/dist/index.js.map +0 -1
  169. package/dist/services/InstallRequestValidator.js.map +0 -1
  170. package/dist/services/InstallationService.js.map +0 -1
  171. package/dist/services/MCPManager.js.map +0 -1
  172. package/dist/services/RequirementService.js.map +0 -1
  173. package/dist/services/ServerService.js.map +0 -1
  174. package/dist/services/TelemetryService.js.map +0 -1
  175. package/dist/utils/UpdateCheckTracker.js.map +0 -1
  176. package/dist/utils/adoUtils.js.map +0 -1
  177. package/dist/utils/clientUtils.js.map +0 -1
  178. package/dist/utils/feedUtils.js.map +0 -1
  179. package/dist/utils/githubAuth.js.map +0 -1
  180. package/dist/utils/githubUtils.js.map +0 -1
  181. package/dist/utils/logger.js.map +0 -1
  182. package/dist/utils/macroExpressionUtils.js.map +0 -1
  183. package/dist/utils/osUtils.js.map +0 -1
  184. package/dist/utils/versionUtils.js.map +0 -1
  185. package/dist/web/contract/serverContract.js.map +0 -1
  186. package/dist/web/server.js.map +0 -1
@@ -0,0 +1,278 @@
1
+ import fs from 'fs/promises';
2
+ import path from 'path';
3
+ import { SETTINGS_DIR } from '../metadatas/constants.js';
4
+ import { SystemSettings } from '../metadatas/types.js';
5
+ import { Logger } from '../../utils/logger.js';
6
+ import { getSystemPythonExecutablePath, getNpmExecutablePath, getBrowserPath } from '../../utils/osUtils.js';
7
+
8
+ const SETTINGS_FILE_NAME = 'system_settings.json';
9
+ const SETTINGS_FILE_PATH = path.join(SETTINGS_DIR, 'settings', SETTINGS_FILE_NAME);
10
+
11
+ export class SystemSettingsManager {
12
+ private static instance: SystemSettingsManager;
13
+ private settings: SystemSettings;
14
+ private settingsFilePath: string;
15
+ private settingsLock: Promise<void> = Promise.resolve();
16
+
17
+ private constructor() {
18
+ this.settingsFilePath = SETTINGS_FILE_PATH;
19
+ this.settings = {};
20
+ // No await here, initialization is best-effort. Lock will protect subsequent calls.
21
+ this.loadSettings().catch(error => {
22
+ Logger.error('Failed to initialize SystemSettingsManager during construction:', error);
23
+ // Initialize with empty settings if load fails, defaults will be applied on first access
24
+ this.settings = {};
25
+ });
26
+ }
27
+
28
+ public static getInstance(): SystemSettingsManager {
29
+ if (!SystemSettingsManager.instance) {
30
+ SystemSettingsManager.instance = new SystemSettingsManager();
31
+ }
32
+ return SystemSettingsManager.instance;
33
+ }
34
+
35
+ private async withLock<T>(operation: () => Promise<T>): Promise<T> {
36
+ const currentLock = this.settingsLock;
37
+ let releaseLock: () => void;
38
+ this.settingsLock = new Promise<void>(resolve => releaseLock = resolve);
39
+ try {
40
+ await currentLock;
41
+ return await operation();
42
+ } finally {
43
+ releaseLock!();
44
+ }
45
+ }
46
+
47
+ // Internal method without lock
48
+ private async _loadSettingsInternal(): Promise<void> {
49
+ try {
50
+ await fs.mkdir(path.dirname(this.settingsFilePath), { recursive: true });
51
+ const data = await fs.readFile(this.settingsFilePath, 'utf-8');
52
+ this.settings = JSON.parse(data);
53
+ await this._applyDefaultsIfNeededInternal(); // Call internal version
54
+ } catch (error) {
55
+ if ((error as NodeJS.ErrnoException).code === 'ENOENT') {
56
+ Logger.info(`Settings file not found at ${this.settingsFilePath}. Initializing with defaults.`);
57
+ this.settings = {};
58
+ await this._applyDefaultsIfNeededInternal(); // Call internal version
59
+ } else {
60
+ Logger.error(`Error loading settings from ${this.settingsFilePath}:`, error);
61
+ this.settings = {};
62
+ await this._applyDefaultsIfNeededInternal(); // Call internal version
63
+ }
64
+ }
65
+ }
66
+
67
+ /**
68
+ * Loads settings from the file. This operation is atomic.
69
+ * If the settings file doesn't exist, it initializes with defaults and creates the file.
70
+ * @returns A promise that resolves when settings are loaded.
71
+ */
72
+ public async loadSettings(): Promise<void> {
73
+ return this.withLock(() => this._loadSettingsInternal());
74
+ }
75
+
76
+ // Internal method without lock
77
+ private async _applyDefaultsIfNeededInternal(): Promise<void> {
78
+ let updated = false;
79
+ const normalizePath = (p?: string) => p ? p.replace(/\\/g, '/') : undefined;
80
+
81
+ if (!this.settings.pythonEnvs) {
82
+ this.settings.pythonEnvs = {};
83
+ updated = true;
84
+ }
85
+
86
+ if (!this.settings.pythonEnvs["system"]) {
87
+ try {
88
+ const pythonPath = normalizePath(await getSystemPythonExecutablePath() || undefined);
89
+ if (pythonPath) {
90
+ this.settings.pythonEnvs["system"] = pythonPath;
91
+ updated = true;
92
+ }
93
+ } catch (e) {
94
+ Logger.warn(`Could not get default pythonEnv: ${e}`);
95
+ }
96
+ }
97
+
98
+ if (!this.settings.nodePath) {
99
+ try {
100
+ const npmExecDir = await getNpmExecutablePath();
101
+ let nodeExecutable = process.platform === 'win32' ? 'node.exe' : 'node';
102
+ const platformNodePath = process.platform === 'win32'
103
+ ? path.join(npmExecDir || '', nodeExecutable)
104
+ : path.join(npmExecDir || '', 'bin', nodeExecutable);
105
+ this.settings.nodePath = npmExecDir ? normalizePath(platformNodePath) : undefined;
106
+ if (this.settings.nodePath) updated = true;
107
+ } catch (e) {
108
+ Logger.warn(`Could not get default nodePath: ${e}`);
109
+ }
110
+ } else {
111
+ this.settings.nodePath = normalizePath(this.settings.nodePath);
112
+ }
113
+
114
+ if (!this.settings.browserPath) {
115
+ try {
116
+ this.settings.browserPath = normalizePath(await getBrowserPath() || undefined);
117
+ if (this.settings.browserPath) updated = true;
118
+ } catch (e) {
119
+ Logger.warn(`Could not get default browserPath: ${e}`);
120
+ }
121
+ } else {
122
+ this.settings.browserPath = normalizePath(this.settings.browserPath);
123
+ }
124
+
125
+ if (!this.settings.systemEnvironments) {
126
+ this.settings.systemEnvironments = { ...process.env } as Record<string, string>;
127
+ updated = true;
128
+ }
129
+ if (this.settings.userConfigurations === undefined) {
130
+ this.settings.userConfigurations = {};
131
+ updated = true;
132
+ }
133
+
134
+ if (updated) {
135
+ await this._saveSettingsInternal();
136
+ }
137
+ }
138
+
139
+ /**
140
+ * Applies default values to settings if they are not already set.
141
+ * This operation is atomic and saves settings if defaults are applied.
142
+ * @returns A promise that resolves when defaults are applied and saved if necessary.
143
+ */
144
+ public async applyDefaultsIfNeeded(): Promise<void> {
145
+ return this.withLock(() => this._applyDefaultsIfNeededInternal());
146
+ }
147
+
148
+ /**
149
+ * Retrieves the current system settings.
150
+ * If settings haven't been loaded or are empty, it attempts to load them.
151
+ * Paths within the settings are normalized (e.g., backslashes to forward slashes).
152
+ * @returns A promise that resolves to the `SystemSettings` object.
153
+ */
154
+ public async getSystemSettings(): Promise<SystemSettings> {
155
+ // Ensure settings are loaded if they are empty.
156
+ if (Object.keys(this.settings).length === 0) {
157
+ // Use the public, locked version of loadSettings here
158
+ await this.loadSettings();
159
+ }
160
+ // Return a deep copy to prevent external modification of the internal state.
161
+ // Ensure this.settings is used, not a potentially stale local copy.
162
+ const settingsToReturn = JSON.parse(JSON.stringify(this.settings));
163
+
164
+ // Ensure paths are normalized when retrieved
165
+ const normalizedSettings = { ...settingsToReturn };
166
+
167
+ // Normalize paths in pythonEnvs
168
+ if (normalizedSettings.pythonEnvs) {
169
+ const normalizedPythonEnvs: Record<string, string> = {};
170
+ Object.keys(normalizedSettings.pythonEnvs).forEach(key => {
171
+ normalizedPythonEnvs[key] = normalizedSettings.pythonEnvs?.[key]?.replace(/\\/g, '/') || '';
172
+ });
173
+ normalizedSettings.pythonEnvs = normalizedPythonEnvs;
174
+ }
175
+
176
+ normalizedSettings.nodePath = normalizedSettings.nodePath?.replace(/\\/g, '/');
177
+ normalizedSettings.browserPath = normalizedSettings.browserPath?.replace(/\\/g, '/');
178
+ return normalizedSettings;
179
+ }
180
+
181
+ /**
182
+ * Creates or updates system settings with the provided partial settings.
183
+ * This operation is atomic and protected by a lock.
184
+ * It loads existing settings if not already loaded, merges the new settings,
185
+ * applies any necessary defaults, and then saves the updated settings.
186
+ * @param newSettings A `Partial<SystemSettings>` object containing the settings to update.
187
+ * @returns A promise that resolves to the fully updated and normalized `SystemSettings`.
188
+ */
189
+ public async createOrUpdateSystemSettings(newSettings: Partial<SystemSettings>): Promise<SystemSettings> {
190
+ return this.withLock(async () => {
191
+ // Ensure current settings are loaded before modification by calling the internal, non-locking version
192
+ if (Object.keys(this.settings).length === 0) {
193
+ await this._loadSettingsInternal();
194
+ }
195
+
196
+ const normalizePath = (p?: string) => p ? p.replace(/\\/g, '/') : undefined;
197
+
198
+ // Initialize pythonEnvs if it doesn't exist on the current settings
199
+ if (!this.settings.pythonEnvs) {
200
+ this.settings.pythonEnvs = {};
201
+ }
202
+
203
+ // Create a new settings object by merging current and new settings.
204
+ const updatedSettings: SystemSettings = {
205
+ ...this.settings, // Start with current settings
206
+ ...newSettings, // Override with new settings
207
+ // Explicitly handle potentially undefined paths from newSettings
208
+ nodePath: normalizePath(newSettings.nodePath !== undefined ? newSettings.nodePath : this.settings.nodePath),
209
+ browserPath: normalizePath(newSettings.browserPath !== undefined ? newSettings.browserPath : this.settings.browserPath),
210
+ // Ensure systemEnvironments and userConfigurations are properly merged or taken from newSettings
211
+ systemEnvironments: newSettings.systemEnvironments !== undefined
212
+ ? newSettings.systemEnvironments
213
+ : this.settings.systemEnvironments, // Keep existing if not in newSettings
214
+ userConfigurations: newSettings.userConfigurations !== undefined
215
+ ? newSettings.userConfigurations
216
+ : this.settings.userConfigurations || {}, // Keep existing or default to empty
217
+ };
218
+
219
+ this.settings = updatedSettings;
220
+
221
+ // Call the internal, non-locking version of applyDefaultsIfNeeded
222
+ await this._applyDefaultsIfNeededInternal();
223
+
224
+ // _applyDefaultsIfNeededInternal will call _saveSettingsInternal if it makes changes.
225
+ // However, if newSettings were provided that didn't trigger a change in _applyDefaultsIfNeededInternal
226
+ // (e.g., just updating an existing path), we still need to save.
227
+ // So, always call _saveSettingsInternal to persist all merged changes.
228
+ await this._saveSettingsInternal();
229
+
230
+ Logger.info('System settings updated.');
231
+ // getSystemSettings will handle its own locking if it needs to load.
232
+ return this.getSystemSettings();
233
+ });
234
+ }
235
+
236
+ /**
237
+ * Internal method to save settings to the file without acquiring a lock.
238
+ * Assumes the lock is already held by the calling public method.
239
+ * Normalizes paths before saving.
240
+ * @returns A promise that resolves when settings are written to disk.
241
+ */
242
+ private async _saveSettingsInternal(): Promise<void> {
243
+ try {
244
+ // Normalize paths before saving
245
+ const settingsToSave = { ...this.settings };
246
+ settingsToSave.nodePath = settingsToSave.nodePath?.replace(/\\/g, '/');
247
+ settingsToSave.browserPath = settingsToSave.browserPath?.replace(/\\/g, '/');
248
+
249
+ if (settingsToSave.pythonEnvs) {
250
+ const normalizedPythonEnvs: Record<string, string> = {};
251
+ Object.keys(settingsToSave.pythonEnvs).forEach(key => {
252
+ normalizedPythonEnvs[key] = settingsToSave.pythonEnvs?.[key]?.replace(/\\/g, '/') || '';
253
+ });
254
+ settingsToSave.pythonEnvs = normalizedPythonEnvs;
255
+ }
256
+
257
+ await fs.mkdir(path.dirname(this.settingsFilePath), { recursive: true });
258
+ await fs.writeFile(this.settingsFilePath, JSON.stringify(settingsToSave, null, 2));
259
+ Logger.info(`System settings saved to ${this.settingsFilePath}`);
260
+ } catch (error) {
261
+ Logger.error(`Error saving settings to ${this.settingsFilePath}:`, error);
262
+ throw error; // Re-throw to indicate failure
263
+ }
264
+ }
265
+
266
+ /**
267
+ * Saves the current settings to the file. This operation is atomic and protected by a lock.
268
+ * Paths are normalized before saving.
269
+ * @returns A promise that resolves when the settings are saved.
270
+ */
271
+ public async saveSettings(): Promise<void> {
272
+ await this.withLock(async () => {
273
+ await this._saveSettingsInternal();
274
+ });
275
+ }
276
+ }
277
+
278
+ export const systemSettingsManager = SystemSettingsManager.getInstance();
@@ -0,0 +1,122 @@
1
+ import os from 'os';
2
+ import path from 'path';
3
+
4
+ /**
5
+ * Defines constants used across the application.
6
+ */
7
+
8
+ /**
9
+ * GitHub repository configuration for feeds
10
+ */
11
+ export const GITHUB_REPO = {
12
+ url: 'https://github.com/ai-microsoft/imcp-feed.git',
13
+ repoName: 'ai-microsoft/imcp-feed',
14
+ feedsPath: 'feeds',
15
+ feedAssetsName: 'imcp-feeds-${latest}.zip',
16
+ };
17
+
18
+ /**
19
+ * Local settings directory path based on OS
20
+ */
21
+ export const SETTINGS_DIR = (() => {
22
+ switch (process.platform) {
23
+ case 'win32':
24
+ return path.join(os.homedir(), '.imcp');
25
+ default: // linux, darwin (macOS), etc.
26
+ return path.join(os.homedir(), '.imcp');
27
+ }
28
+ })();
29
+
30
+ /**
31
+ * Local feeds directory path
32
+ */
33
+ export const LOCAL_FEEDS_DIR = path.join(SETTINGS_DIR, 'feeds');
34
+
35
+ /**
36
+ * Path to the user information file
37
+ */
38
+ export const USER_INFO_PATH = path.join(SETTINGS_DIR, 'settings', 'user_info.json');
39
+
40
+ /**
41
+ * Path to the local feeds schema directory
42
+ */
43
+ export const LOCAL_FEEDS_SCHEMA_DIR = path.join(LOCAL_FEEDS_DIR, 'schemas');
44
+
45
+ const CODE_STRORAGE_DIR = (() => {
46
+ switch (process.platform) {
47
+ case 'win32':
48
+ return path.join(os.homedir(), 'AppData', 'Roaming', 'Code', 'User');
49
+ case 'darwin': // macOS
50
+ return path.join(os.homedir(), 'Library', 'Application Support', 'Code', 'User');
51
+ default: // linux
52
+ return path.join(os.homedir(), '.config', 'Code', 'User');
53
+ }
54
+ })();
55
+
56
+ const CODE_INSIDER_STRORAGE_DIR = (() => {
57
+ switch (process.platform) {
58
+ case 'win32':
59
+ return path.join(os.homedir(), 'AppData', 'Roaming', 'Code - Insiders', 'User');
60
+ case 'darwin': // macOS
61
+ return path.join(os.homedir(), 'Library', 'Application Support', 'Code - Insiders', 'User');
62
+ default: // linux
63
+ return path.join(os.homedir(), '.config', 'Code - Insiders', 'User');
64
+ }
65
+ })();
66
+
67
+ /**
68
+ * Supported client configurations.
69
+ * Key: Client name (e.g., 'vscode')
70
+ * Value: Client-specific settings or configuration details.
71
+ * TODO: Define actual client settings structure.
72
+ */
73
+ export const SUPPORTED_CLIENTS: Record<string, {
74
+ extension: {
75
+ extensionId: string;
76
+ leastVersion?: string;
77
+ repository?: string;
78
+ assetName?: string;
79
+ private?: boolean;
80
+ };
81
+ codeSettingPath: string;
82
+ codeInsiderSettingPath: string;
83
+ }> = {
84
+ 'MSRooCode': {
85
+
86
+ extension: {
87
+ extensionId: 'microsoftai.ms-roo-cline',
88
+ leastVersion: '0.0.8',
89
+ repository: 'ai-microsoft/roo-cline',
90
+ assetName: 'ms-roo-cline-${version}.vsix',
91
+ private: true
92
+ },
93
+ codeSettingPath: path.join(CODE_STRORAGE_DIR, 'globalStorage', 'microsoftai.ms-roo-cline', 'settings', 'cline_mcp_settings.json'),
94
+ codeInsiderSettingPath: path.join(CODE_INSIDER_STRORAGE_DIR, 'globalStorage', 'microsoftai.ms-roo-cline', 'settings', 'cline_mcp_settings.json'),
95
+ },
96
+ 'Cline': { /* VS Code specific settings */
97
+ extension: {
98
+ extensionId: 'saoudrizwan.claude-dev',
99
+ },
100
+ codeSettingPath: path.join(CODE_STRORAGE_DIR, 'globalStorage', 'saoudrizwan.claude-dev', 'settings', 'cline_mcp_settings.json'),
101
+ codeInsiderSettingPath: path.join(CODE_INSIDER_STRORAGE_DIR, 'globalStorage', 'saoudrizwan.claude-dev', 'settings', 'cline_mcp_settings.json'),
102
+ },
103
+ 'GithubCopilot': { /* GitHub Copilot specific settings */
104
+ extension: {
105
+ extensionId: 'github.copilot',
106
+ },
107
+ codeSettingPath: path.join(CODE_STRORAGE_DIR, 'settings.json'),
108
+ codeInsiderSettingPath: path.join(CODE_INSIDER_STRORAGE_DIR, 'settings.json'),
109
+ },
110
+ // Add other supported clients here
111
+ };
112
+
113
+ /**
114
+ * List of supported client names.
115
+ */
116
+ export const SUPPORTED_CLIENT_NAMES = Object.keys(SUPPORTED_CLIENTS);
117
+
118
+ /**
119
+ * Minimum time between requirement update checks (in milliseconds)
120
+ * 10 minutes = 10 * 60 * 1000 = 600000 ms
121
+ */
122
+ export const UPDATE_CHECK_INTERVAL_MS = 10 * 60 * 1000; // 10 minutes
@@ -0,0 +1,65 @@
1
+ /**
2
+ * Step name constants for InstallOperationManager and step recording.
3
+ *
4
+ * This file defines all static step names and documents dynamic step name patterns
5
+ * used throughout the installation and onboarding process.
6
+ *
7
+ * Dynamic step names are documented as template string patterns.
8
+ */
9
+
10
+ /** Step for processing all requirement updates in a batch operation. */
11
+ export const STEP_PROCESS_REQUIREMENT_UPDATES = 'Processing all requirement updates';
12
+
13
+ /** Step for checking the status of a specific requirement. */
14
+ export const STEP_CHECKING_REQUIREMENT_STATUS = 'Checking the status of requirement';
15
+
16
+ /** Step for installing requirements in the background process. */
17
+ export const STEP_INSTALLING_REQUIREMENTS_IN_BACKGROUND = 'Installing requirements in the background';
18
+
19
+ /** Step for running the install logic in the NugetInstaller. */
20
+ export const STEP_NUGET_INSTALLER_INSTALL = 'Running install in NugetInstaller';
21
+
22
+ /** Step for checking and installing all requirements as needed. */
23
+ export const STEP_CHECK_AND_INSTALL_REQUIREMENTS = 'Checking and installing all requirements';
24
+
25
+ /** Step for running the install logic in the CommandInstaller. */
26
+ export const STEP_COMMAND_INSTALLER_INSTALL = 'Running install in CommandInstaller';
27
+
28
+ /** Step for running the install logic in the GeneralInstaller. */
29
+ export const STEP_GENERAL_INSTALLER_INSTALL = 'Running install in GeneralInstaller';
30
+
31
+ /** Step for executing the actual installation command (npm, pip, etc.). */
32
+ export const STEP_INSTALLATION_COMMAND_EXECUTION = 'Executing installation command for requirement';
33
+
34
+ /** Step for running the install logic in the PipInstaller. */
35
+ export const STEP_PIP_INSTALLER_INSTALL = 'Running install in PipInstaller';
36
+
37
+ /** Step for processing requirement updates in the RequirementService. */
38
+ export const STEP_PROCESS_REQUIREMENT_UPDATES_SERVICE = 'Processing requirement updates in RequirementService';
39
+
40
+ /** Step for checking if the server is ready after installation. */
41
+ export const STEP_CHECK_SERVER_READINESS = 'Checking server readiness after installation';
42
+
43
+ /** Step for running the install logic in the NpmInstaller. */
44
+ export const STEP_NPM_INSTALLER_INSTALL = 'Running install in NpmInstaller';
45
+
46
+ /** Prefix for steps that update a specific requirement. */
47
+ export const STEP_INSTALL_REQUIREMENT_PREFIX = 'Updating requirement:';
48
+
49
+ /** Prefix for steps that execute an installation command for a requirement. */
50
+ export const STEP_INSTALL_COMMAND_PREFIX = 'Executing installation command for:';
51
+
52
+ /** Step for checking and installing the VS Code extension for the client. */
53
+ export const STEP_CHECK_VSCODE_AND_INSTALL_EXTENSION = 'Checking and installing VS Code extension for client';
54
+
55
+ /** Step for setting up the installation configuration (env, args, etc.). */
56
+ export const STEP_SETUP_INSTALLATION_CONFIG = 'Setting up installation configuration';
57
+
58
+ /** Step for updating VS Code settings for the client/server. */
59
+ export const STEP_UPDATE_VSCODE_SETTINGS = 'Updating VS Code settings for client/server';
60
+
61
+ /** Step for the overall installation process of a client or server. */
62
+ export const STEP_INSTALLATION = 'Running overall installation process';
63
+
64
+ /** Step for marking the initiation of an onboarding or installation process. */
65
+ export const STEP_INITIATED = 'Initiating onboarding or installation process';
@@ -0,0 +1,202 @@
1
+ export enum OSType {
2
+ Windows = 'windows',
3
+ MacOS = 'macos',
4
+ Linux = 'linux'
5
+ }
6
+
7
+ export interface RequirementStatus {
8
+ name: string;
9
+ type: string;
10
+ installed: boolean;
11
+ inProgress?: boolean;
12
+ version?: string;
13
+ error?: string;
14
+ availableUpdate?: {
15
+ version: string;
16
+ message: string;
17
+ };
18
+ lastCheckTime?: string;
19
+ operationStatus?: OperationStatus;
20
+ pythonEnv?: string; // Store Python environment path for pip requirements
21
+ npmPath?: string; // Path to the installed npm package path
22
+ }
23
+
24
+ export interface MCPServerStatus {
25
+ installedStatus: Record<string, OperationStatus>; // client: installed
26
+ name: string;
27
+ error?: string;
28
+ }
29
+
30
+ export interface OperationStatus {
31
+ status: 'pending' | 'in-progress' | 'completed' | 'failed';
32
+ type: 'install' | 'uninstall' | 'update' | 'check';
33
+ target: 'requirement' | 'server';
34
+ message?: string;
35
+ error?: string;
36
+ operationId?: string; // Added to track async operations
37
+ }
38
+
39
+ export interface InstallationStatus {
40
+ requirementsStatus: Record<string, RequirementStatus>;
41
+ serversStatus: Record<string, MCPServerStatus>;
42
+ lastUpdated: string;
43
+ }
44
+
45
+ export interface MCPServerCategory {
46
+ name: string;
47
+ displayName: string;
48
+ description?: string;
49
+ type: 'local';
50
+ path?: string;
51
+ installationStatus?: InstallationStatus;
52
+ feedConfiguration?: FeedConfiguration;
53
+ }
54
+
55
+ export interface ServerCategoryListOptions {
56
+ local?: boolean;
57
+ }
58
+
59
+ export interface ServerOperationResult {
60
+ success: boolean;
61
+ message?: string;
62
+ error?: Error;
63
+ output?: string; // Added to capture installation logs
64
+ status?: OperationStatus[]; // Added to capture operation status
65
+ }
66
+
67
+ export interface MCPConfiguration {
68
+ localServerCategories: MCPServerCategory[];
69
+ feeds: Record<string, FeedConfiguration>;
70
+ clientMCPSettings?: Record<string, Record<string, any>>;
71
+ }
72
+
73
+ export interface ServerInstallOptions {
74
+ force?: boolean;
75
+ env?: Record<string, string>; // Environment variables for installation
76
+ targetClients?: string[]; // Target clients for configuration
77
+ requirements?: RequirementConfig[];
78
+ args?: string[]; // Arguments for installation
79
+ settings?: Record<string, any>; // Settings for installation like python env
80
+ }
81
+
82
+ export interface UpdateRequirementOptions {
83
+ requirementName: string;
84
+ updateVersion: string;
85
+ }
86
+
87
+ export interface ServerUninstallOptions {
88
+ removeData?: boolean;
89
+ targets?: string[]; // List of client targets to uninstall from
90
+ }
91
+
92
+ // Types related to server feed configuration (e.g., ai-coder-tools.json)
93
+ export interface EnvVariableConfig {
94
+ Required: boolean;
95
+ Description: string;
96
+ Default?: string;
97
+ }
98
+
99
+ export interface InstallationConfig {
100
+ command: string;
101
+ args: string[]; // Can use ${packageSource} as template variable for installation path
102
+ env?: Record<string, EnvVariableConfig>; // Note the colon in property name
103
+ url?: string; // URL for sse mode
104
+ }
105
+
106
+ export interface DependencyConfig {
107
+ requirements?: Array<{
108
+ name: string;
109
+ version: string;
110
+ order?: number;
111
+ }>;
112
+ mcpServers?: Array<{
113
+ name: string;
114
+ }>;
115
+ }
116
+
117
+ export interface McpConfig {
118
+ name: string;
119
+ description: string;
120
+ mode: 'stdio' | 'sse'; // Currently only stdio mode is supported in ai-coder-tools
121
+ dependencies?: DependencyConfig;
122
+ schemas?: string; // Path to the schema file
123
+ repository?: string; // Repository URL for the server
124
+ systemTags?: Record<string, string>; // System tags for the feed
125
+ installation: InstallationConfig;
126
+ }
127
+
128
+ export interface RegistryConfig {
129
+ githubRelease?: {
130
+ repository: string;
131
+ assetsName?: string; // Template string like "ai-coder-tools-${latest}.zip"
132
+ assetName: string; // Template string like "ai-coder-tools-${latest}.tgz"
133
+ };
134
+ artifacts?: {
135
+ registryUrl: string;
136
+ registryName: string; // Name of the registry
137
+ };
138
+ }
139
+
140
+ export interface RequirementConfig {
141
+ name: string;
142
+ type: 'npm' | 'pip' | 'command' | 'extension' | 'nuget' | 'other'; // Add other requirement types if needed
143
+ alias?: string; // Alias for the command type
144
+ version: string;
145
+ registry?: RegistryConfig;
146
+ }
147
+
148
+ export interface FeedConfiguration {
149
+ name: string;
150
+ displayName: string;
151
+ description: string;
152
+ repository?: string;
153
+ PullRequest?: string; // Optional Pull Request link
154
+ requirements: RequirementConfig[];
155
+ mcpServers: McpConfig[];
156
+ systemTags?: Record<string, string>; // System tags for the feed
157
+ }
158
+
159
+ export interface ClientSettings {
160
+ codeSettingPath: string;
161
+ codeInsiderSettingPath: string;
162
+ }
163
+
164
+ // Events that can be emitted by the SDK
165
+ export enum MCPEvent {
166
+ SERVER_INSTALLED = 'server:installed',
167
+ SERVER_UNINSTALLED = 'server:uninstalled',
168
+ SERVER_STARTED = 'server:started',
169
+ SERVER_STOPPED = 'server:stopped',
170
+ CONFIG_CHANGED = 'config:changed',
171
+ }
172
+
173
+ export interface MCPEventData {
174
+ [MCPEvent.SERVER_INSTALLED]: { server: MCPServerCategory };
175
+ [MCPEvent.SERVER_UNINSTALLED]: { serverName: string; targets?: string[] };
176
+ [MCPEvent.SERVER_STARTED]: { server: MCPServerCategory };
177
+ [MCPEvent.SERVER_STOPPED]: { serverName: string };
178
+ [MCPEvent.CONFIG_CHANGED]: { configuration: MCPConfiguration };
179
+ }
180
+
181
+ export interface InstallOperationStep {
182
+ name: string;
183
+ status: 'pending' | 'in-progress' | 'completed' | 'failed' | 'canceled';
184
+ message?: string;
185
+ isCritical?: boolean;
186
+ timestamp: string;
187
+ }
188
+
189
+ export interface InstallOperationDetails {
190
+ currentStep: string;
191
+ steps: InstallOperationStep[];
192
+ lastUpdated: string;
193
+ error?: string;
194
+ overallStatus: 'pending' | 'in-progress' | 'completed' | 'failed';
195
+ }
196
+ export interface SystemSettings {
197
+ pythonEnvs?: Record<string, string>;
198
+ nodePath?: string;
199
+ browserPath?: string;
200
+ systemEnvironments?: Record<string, string>;
201
+ userConfigurations?: Record<string, string>;
202
+ }