stigmergy 1.2.6 → 1.2.8

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 (59) hide show
  1. package/README.md +32 -17
  2. package/STIGMERGY.md +16 -7
  3. package/docs/MULTI_USER_WIKI_COLLABORATION_SYSTEM.md +523 -0
  4. package/docs/PROMPT_BASED_SKILLS_SYSTEM_DESIGN.md +458 -0
  5. package/docs/SKILL_IMPLEMENTATION_CONSTRAINTS_AND_ALIGNMENT.md +423 -0
  6. package/docs/TECHNICAL_FEASIBILITY_ANALYSIS.md +308 -0
  7. package/examples/multilingual-hook-demo.js +125 -0
  8. package/package.json +14 -17
  9. package/scripts/dependency-analyzer.js +101 -0
  10. package/scripts/generate-cli-docs.js +64 -0
  11. package/scripts/postuninstall.js +46 -0
  12. package/scripts/preuninstall.js +75 -0
  13. package/scripts/run-layered-tests.js +3 -3
  14. package/src/adapters/claude/install_claude_integration.js +17 -17
  15. package/src/adapters/codebuddy/install_codebuddy_integration.js +13 -13
  16. package/src/adapters/codex/install_codex_integration.js +27 -27
  17. package/src/adapters/copilot/install_copilot_integration.js +46 -46
  18. package/src/adapters/gemini/install_gemini_integration.js +10 -10
  19. package/src/adapters/iflow/install_iflow_integration.js +7 -7
  20. package/src/adapters/qoder/install_qoder_integration.js +12 -12
  21. package/src/adapters/qwen/install_qwen_integration.js +17 -17
  22. package/src/auth.js +173 -173
  23. package/src/auth_command.js +208 -208
  24. package/src/calculator.js +313 -313
  25. package/src/cli/router.js +151 -7
  26. package/src/core/cache_cleaner.js +767 -767
  27. package/src/core/cli_help_analyzer.js +680 -680
  28. package/src/core/cli_parameter_handler.js +132 -132
  29. package/src/core/cli_tools.js +89 -89
  30. package/src/core/coordination/index.js +16 -16
  31. package/src/core/coordination/nodejs/AdapterManager.js +102 -102
  32. package/src/core/coordination/nodejs/CLCommunication.js +132 -132
  33. package/src/core/coordination/nodejs/CLIIntegrationManager.js +272 -272
  34. package/src/core/coordination/nodejs/HealthChecker.js +76 -76
  35. package/src/core/coordination/nodejs/HookDeploymentManager.js +463 -274
  36. package/src/core/coordination/nodejs/StatisticsCollector.js +71 -71
  37. package/src/core/coordination/nodejs/index.js +90 -90
  38. package/src/core/coordination/nodejs/utils/Logger.js +29 -29
  39. package/src/core/enhanced_installer.js +479 -479
  40. package/src/core/enhanced_uninstaller.js +638 -638
  41. package/src/core/error_handler.js +406 -406
  42. package/src/core/installer.js +32 -32
  43. package/src/core/memory_manager.js +83 -83
  44. package/src/core/multilingual/language-pattern-manager.js +172 -0
  45. package/src/core/rest_client.js +160 -160
  46. package/src/core/smart_router.js +261 -249
  47. package/src/core/upgrade_manager.js +48 -20
  48. package/src/data_encryption.js +143 -143
  49. package/src/data_structures.js +440 -440
  50. package/src/deploy.js +55 -55
  51. package/src/index.js +30 -30
  52. package/src/test/cli-availability-checker.js +194 -194
  53. package/src/test/test-environment.js +289 -289
  54. package/src/utils/helpers.js +35 -35
  55. package/src/utils.js +921 -921
  56. package/src/weatherProcessor.js +228 -228
  57. package/test/multilingual/hook-deployment.test.js +91 -0
  58. package/test/multilingual/language-pattern-manager.test.js +140 -0
  59. package/test/multilingual/system-test.js +85 -0
@@ -1,479 +1,479 @@
1
- /**
2
- * Enhanced Stigmergy Installer
3
- *
4
- * Automatic cache cleaning before installation with comprehensive error handling
5
- * and progress reporting.
6
- */
7
-
8
- const fs = require('fs');
9
- const path = require('path');
10
- const os = require('os');
11
- const CacheCleaner = require('./cache_cleaner');
12
- const StigmergyInstaller = require('./installer');
13
-
14
- class EnhancedInstaller {
15
- constructor(options = {}) {
16
- this.options = {
17
- cleanBeforeInstall: options.cleanBeforeInstall !== false, // Default true
18
- cleanNPXCache: options.cleanNPXCache !== false,
19
- cleanTempFiles: options.cleanTempFiles !== false,
20
- cleanOldVersions: options.cleanOldVersions !== false,
21
- dryRun: options.dryRun || false,
22
- force: options.force || false,
23
- verbose: options.verbose || false,
24
- ...options,
25
- };
26
-
27
- this.baseInstaller = new StigmergyInstaller();
28
- this.cacheCleaner = new CacheCleaner({
29
- dryRun: this.options.dryRun,
30
- force: this.options.force,
31
- verbose: this.options.verbose,
32
- });
33
-
34
- this.results = {
35
- cacheCleaning: {},
36
- installation: {},
37
- errors: [],
38
- };
39
- }
40
-
41
- /**
42
- * Perform enhanced installation with automatic cache cleaning
43
- */
44
- async enhancedInstall(options = {}) {
45
- const config = {
46
- cleanStigmergy: true,
47
- cleanNPX: this.options.cleanNPXCache,
48
- cleanNPM: this.options.cleanOldVersions,
49
- cleanCLI: false,
50
- cleanTemp: this.options.cleanTempFiles,
51
- ...options,
52
- };
53
-
54
- console.log('🚀 Starting Enhanced Stigmergy Installation...\n');
55
-
56
- if (this.options.dryRun) {
57
- console.log('🔍 DRY RUN MODE - No actual changes will be made\n');
58
- }
59
-
60
- try {
61
- // Step 1: Pre-installation cache cleaning
62
- if (this.options.cleanBeforeInstall) {
63
- await this.preInstallCacheClean(config);
64
- }
65
-
66
- // Step 2: Scan and prepare for installation
67
- await this.scanAndPrepare();
68
-
69
- // Step 3: Perform installation
70
- if (!this.options.dryRun) {
71
- await this.performInstallation();
72
- }
73
-
74
- // Step 4: Post-installation verification
75
- await this.verifyInstallation();
76
-
77
- // Step 5: Print summary
78
- this.printSummary();
79
-
80
- return this.results;
81
- } catch (error) {
82
- console.error('�?Enhanced installation failed:', error.message);
83
- this.results.errors.push(error.message);
84
- return this.results;
85
- }
86
- }
87
-
88
- /**
89
- * Pre-installation cache cleaning
90
- */
91
- async preInstallCacheClean(config) {
92
- console.log('🧹 Pre-installation Cache Cleaning...\n');
93
-
94
- const startTime = Date.now();
95
-
96
- try {
97
- // Clean caches before installation
98
- const cacheResults = await this.cacheCleaner.cleanAllCaches(config);
99
-
100
- const endTime = Date.now();
101
- const duration = endTime - startTime;
102
-
103
- this.results.cacheCleaning = {
104
- success: true,
105
- duration,
106
- filesRemoved: cacheResults.filesRemoved,
107
- directoriesRemoved: cacheResults.directoriesRemoved,
108
- bytesFreed: cacheResults.bytesFreed,
109
- errors: cacheResults.errors.length,
110
- };
111
-
112
- console.log(`�?Cache cleaning completed in ${duration}ms`);
113
- console.log(
114
- `📊 Removed ${cacheResults.filesRemoved} files, freed ${this.formatBytes(cacheResults.bytesFreed)}\n`,
115
- );
116
- } catch (error) {
117
- console.error('�?Cache cleaning failed:', error.message);
118
- this.results.cacheCleaning = {
119
- success: false,
120
- error: error.message,
121
- };
122
-
123
- if (!this.options.force) {
124
- throw new Error(`Cache cleaning failed: ${error.message}`);
125
- }
126
-
127
- console.log(
128
- '⚠️ Continuing installation despite cache cleaning errors...\n',
129
- );
130
- }
131
- }
132
-
133
- /**
134
- * Scan system and prepare for installation
135
- */
136
- async scanAndPrepare() {
137
- console.log('🔍 Scanning System for Installation...\n');
138
-
139
- try {
140
- // Check system requirements
141
- await this.checkSystemRequirements();
142
-
143
- // Scan for existing CLI tools
144
- const scanResult = await this.baseInstaller.scanCLI();
145
-
146
- console.log('�?System scan completed');
147
- console.log(
148
- `📊 Found ${Object.keys(scanResult.available).length} available CLI tools`,
149
- );
150
- console.log(
151
- `📊 Missing ${Object.keys(scanResult.missing).length} CLI tools\n`,
152
- );
153
-
154
- this.results.scan = scanResult;
155
- } catch (error) {
156
- console.error('�?System scan failed:', error.message);
157
- throw error;
158
- }
159
- }
160
-
161
- /**
162
- * Perform the actual installation
163
- */
164
- async performInstallation() {
165
- console.log('📦 Performing Installation...\n');
166
-
167
- try {
168
- // Interactive tool selection would go here
169
- // For now, we'll use a simple approach
170
- const missingTools = Object.keys(this.results.scan.missing);
171
-
172
- if (missingTools.length === 0) {
173
- console.log('ℹ️ All CLI tools are already installed');
174
- this.results.installation = {
175
- success: true,
176
- installed: [],
177
- message: 'No tools needed installation',
178
- };
179
- return;
180
- }
181
-
182
- console.log(`📦 Installing ${missingTools.length} CLI tools...`);
183
-
184
- // Install missing tools
185
- const installResult = await this.baseInstaller.installTools(
186
- missingTools,
187
- this.results.scan.missing,
188
- );
189
-
190
- this.results.installation = {
191
- success: true,
192
- installed: missingTools,
193
- result: installResult,
194
- };
195
-
196
- console.log('�?Installation completed');
197
- } catch (error) {
198
- console.error('�?Installation failed:', error.message);
199
- this.results.installation = {
200
- success: false,
201
- error: error.message,
202
- };
203
- throw error;
204
- }
205
- }
206
-
207
- /**
208
- * Post-installation verification
209
- */
210
- async verifyInstallation() {
211
- console.log('\n�?Post-installation Verification...');
212
-
213
- try {
214
- // Verify installation was successful
215
- const postScan = await this.baseInstaller.scanCLI();
216
-
217
- const verificationResults = {
218
- beforeCount: Object.keys(this.results.scan.available).length,
219
- afterCount: Object.keys(postScan.available).length,
220
- newlyInstalled: [],
221
- };
222
-
223
- // Find newly installed tools
224
- for (const tool of Object.keys(postScan.available)) {
225
- if (!this.results.scan.available[tool]) {
226
- verificationResults.newlyInstalled.push(tool);
227
- }
228
- }
229
-
230
- this.results.verification = verificationResults;
231
-
232
- console.log(`📊 CLI tools before: ${verificationResults.beforeCount}`);
233
- console.log(`📊 CLI tools after: ${verificationResults.afterCount}`);
234
- console.log(
235
- `📊 Newly installed: ${verificationResults.newlyInstalled.length}`,
236
- );
237
-
238
- if (verificationResults.newlyInstalled.length > 0) {
239
- console.log(
240
- `�?Successfully installed: ${verificationResults.newlyInstalled.join(', ')}`,
241
- );
242
- }
243
-
244
- console.log('�?Installation verification completed\n');
245
- } catch (error) {
246
- console.error('�?Verification failed:', error.message);
247
- this.results.errors.push(`Verification: ${error.message}`);
248
- }
249
- }
250
-
251
- /**
252
- * Check system requirements
253
- */
254
- async checkSystemRequirements() {
255
- console.log('🔧 Checking System Requirements...');
256
-
257
- // Check Node.js version
258
- const nodeVersion = process.version;
259
- const majorVersion = parseInt(nodeVersion.slice(1).split('.')[0]);
260
-
261
- if (majorVersion < 14) {
262
- throw new Error(
263
- `Node.js version ${nodeVersion} is not supported. Please use Node.js 14 or higher.`,
264
- );
265
- }
266
-
267
- console.log(` �?Node.js: ${nodeVersion}`);
268
-
269
- // Check npm availability
270
- try {
271
- const { spawnSync } = require('child_process');
272
- const npmResult = spawnSync('npm', ['--version'], {
273
- encoding: 'utf8',
274
- shell: true,
275
- });
276
-
277
- if (npmResult.status === 0) {
278
- console.log(` �?npm: ${npmResult.stdout.trim()}`);
279
- } else {
280
- throw new Error('npm is not available');
281
- }
282
- } catch (error) {
283
- throw new Error('npm is required but not found');
284
- }
285
-
286
- // Check available disk space (basic check)
287
- const homeDir = os.homedir();
288
- try {
289
- const stats = fs.statSync(homeDir);
290
- console.log(` �?Home directory accessible: ${homeDir}`);
291
- } catch (error) {
292
- throw new Error(`Cannot access home directory: ${homeDir}`);
293
- }
294
-
295
- console.log('�?System requirements check passed\n');
296
- }
297
-
298
- /**
299
- * Create installation plan without executing
300
- */
301
- async createInstallationPlan() {
302
- console.log('📋 Creating Installation Plan...\n');
303
-
304
- const plan = {
305
- cacheCleaning: {},
306
- installation: {},
307
- estimatedTime: 0,
308
- estimatedSpace: 0,
309
- };
310
-
311
- try {
312
- // Check what would be cleaned
313
- const stigmergyDir = path.join(os.homedir(), '.stigmergy');
314
- if (fs.existsSync(stigmergyDir)) {
315
- const cacheSize = await this.calculateDirectorySize(stigmergyDir);
316
- plan.cacheCleaning.stigmergyCache = {
317
- path: stigmergyDir,
318
- size: cacheSize,
319
- wouldClean: this.options.cleanBeforeInstall,
320
- };
321
- plan.estimatedSpace += cacheSize;
322
- }
323
-
324
- // Scan for missing CLI tools
325
- const scanResult = await this.baseInstaller.scanCLI();
326
- const missingTools = Object.keys(scanResult.missing);
327
-
328
- plan.installation = {
329
- missingTools: missingTools,
330
- toolCount: missingTools.length,
331
- tools: missingTools.map((tool) => ({
332
- name: scanResult.missing[tool].name,
333
- installCommand: scanResult.missing[tool].install,
334
- })),
335
- };
336
-
337
- // Estimate time (very rough estimate)
338
- plan.estimatedTime = missingTools.length * 30000; // 30 seconds per tool
339
-
340
- console.log('📊 Installation Plan Summary:');
341
- console.log(
342
- ` 🧹 Cache cleaning: ${this.options.cleanBeforeInstall ? 'Yes' : 'No'}`,
343
- );
344
- console.log(` 📦 Tools to install: ${missingTools.length}`);
345
- console.log(
346
- ` ⏱️ Estimated time: ${Math.ceil(plan.estimatedTime / 1000)} seconds`,
347
- );
348
- console.log(
349
- ` 💾 Estimated space: ${this.formatBytes(plan.estimatedSpace)}`,
350
- );
351
-
352
- return plan;
353
- } catch (error) {
354
- console.error('�?Failed to create installation plan:', error.message);
355
- throw error;
356
- }
357
- }
358
-
359
- /**
360
- * Quick cache clean only
361
- */
362
- async quickCacheClean() {
363
- console.log('�?Quick Cache Clean Only...\n');
364
-
365
- try {
366
- const results = await this.cacheCleaner.cleanAllCaches({
367
- cleanStigmergy: false, // Don't clean main config
368
- cleanNPX: true,
369
- cleanNPM: false,
370
- cleanCLI: false,
371
- cleanTemp: true,
372
- });
373
-
374
- console.log('�?Quick cache clean completed');
375
- console.log(
376
- `📊 Removed ${results.filesRemoved} files, freed ${this.formatBytes(results.bytesFreed)}`,
377
- );
378
-
379
- return results;
380
- } catch (error) {
381
- console.error('�?Quick cache clean failed:', error.message);
382
- throw error;
383
- }
384
- }
385
-
386
- /**
387
- * Helper methods
388
- */
389
- async calculateDirectorySize(dirPath) {
390
- let totalSize = 0;
391
-
392
- try {
393
- const items = fs.readdirSync(dirPath, { withFileTypes: true });
394
-
395
- for (const item of items) {
396
- const fullPath = path.join(dirPath, item.name);
397
-
398
- if (item.isDirectory()) {
399
- totalSize += await this.calculateDirectorySize(fullPath);
400
- } else {
401
- try {
402
- const stat = fs.statSync(fullPath);
403
- totalSize += stat.size;
404
- } catch (error) {
405
- // Skip files we can't stat
406
- }
407
- }
408
- }
409
- } catch (error) {
410
- // Return 0 for directories we can't read
411
- }
412
-
413
- return totalSize;
414
- }
415
-
416
- formatBytes(bytes) {
417
- const sizes = ['Bytes', 'KB', 'MB', 'GB'];
418
- if (bytes === 0) return '0 Bytes';
419
- const i = Math.floor(Math.log(bytes) / Math.log(1024));
420
- return Math.round((bytes / Math.pow(1024, i)) * 100) / 100 + ' ' + sizes[i];
421
- }
422
-
423
- printSummary() {
424
- console.log('\n📊 ENHANCED INSTALLATION SUMMARY:');
425
- console.log('='.repeat(50));
426
-
427
- if (this.options.dryRun) {
428
- console.log('🔍 DRY RUN MODE - No actual changes were made');
429
- }
430
-
431
- // Cache cleaning summary
432
- if (this.results.cacheCleaning.success) {
433
- console.log('🧹 Cache Cleaning: �?);
434
- console.log(` Duration: ${this.results.cacheCleaning.duration}ms`);
435
- console.log(
436
- ` Files removed: ${this.results.cacheCleaning.filesRemoved}`,
437
- );
438
- console.log(
439
- ` Space freed: ${this.formatBytes(this.results.cacheCleaning.bytesFreed)}`,
440
- );
441
- } else if (this.results.cacheCleaning.error) {
442
- console.log(`🧹 Cache Cleaning: �?${this.results.cacheCleaning.error}`);
443
- }
444
-
445
- // Installation summary
446
- if (this.results.installation.success) {
447
- console.log('📦 Installation: �?);
448
- if (this.results.installation.installed.length > 0) {
449
- console.log(
450
- ` Installed: ${this.results.installation.installed.join(', ')}`,
451
- );
452
- } else {
453
- console.log(` Message: ${this.results.installation.message}`);
454
- }
455
- } else if (this.results.installation.error) {
456
- console.log(`📦 Installation: �?${this.results.installation.error}`);
457
- }
458
-
459
- // Verification summary
460
- if (this.results.verification) {
461
- console.log('�?Verification: �?);
462
- console.log(
463
- ` Newly installed: ${this.results.verification.newlyInstalled.length} tools`,
464
- );
465
- }
466
-
467
- // Errors
468
- if (this.results.errors.length > 0) {
469
- console.log(`\n�?Errors encountered: ${this.results.errors.length}`);
470
- this.results.errors.forEach((error) => {
471
- console.log(` - ${error}`);
472
- });
473
- }
474
-
475
- console.log('\n🎉 Enhanced installation completed!');
476
- }
477
- }
478
-
479
- module.exports = EnhancedInstaller;
1
+ /**
2
+ * Enhanced Stigmergy Installer
3
+ *
4
+ * Automatic cache cleaning before installation with comprehensive error handling
5
+ * and progress reporting.
6
+ */
7
+
8
+ const fs = require('fs');
9
+ const path = require('path');
10
+ const os = require('os');
11
+ const CacheCleaner = require('./cache_cleaner');
12
+ const StigmergyInstaller = require('./installer');
13
+
14
+ class EnhancedInstaller {
15
+ constructor(options = {}) {
16
+ this.options = {
17
+ cleanBeforeInstall: options.cleanBeforeInstall !== false, // Default true
18
+ cleanNPXCache: options.cleanNPXCache !== false,
19
+ cleanTempFiles: options.cleanTempFiles !== false,
20
+ cleanOldVersions: options.cleanOldVersions !== false,
21
+ dryRun: options.dryRun || false,
22
+ force: options.force || false,
23
+ verbose: options.verbose || false,
24
+ ...options,
25
+ };
26
+
27
+ this.baseInstaller = new StigmergyInstaller();
28
+ this.cacheCleaner = new CacheCleaner({
29
+ dryRun: this.options.dryRun,
30
+ force: this.options.force,
31
+ verbose: this.options.verbose,
32
+ });
33
+
34
+ this.results = {
35
+ cacheCleaning: {},
36
+ installation: {},
37
+ errors: [],
38
+ };
39
+ }
40
+
41
+ /**
42
+ * Perform enhanced installation with automatic cache cleaning
43
+ */
44
+ async enhancedInstall(options = {}) {
45
+ const config = {
46
+ cleanStigmergy: true,
47
+ cleanNPX: this.options.cleanNPXCache,
48
+ cleanNPM: this.options.cleanOldVersions,
49
+ cleanCLI: false,
50
+ cleanTemp: this.options.cleanTempFiles,
51
+ ...options,
52
+ };
53
+
54
+ console.log('🚀 Starting Enhanced Stigmergy Installation...\n');
55
+
56
+ if (this.options.dryRun) {
57
+ console.log('🔍 DRY RUN MODE - No actual changes will be made\n');
58
+ }
59
+
60
+ try {
61
+ // Step 1: Pre-installation cache cleaning
62
+ if (this.options.cleanBeforeInstall) {
63
+ await this.preInstallCacheClean(config);
64
+ }
65
+
66
+ // Step 2: Scan and prepare for installation
67
+ await this.scanAndPrepare();
68
+
69
+ // Step 3: Perform installation
70
+ if (!this.options.dryRun) {
71
+ await this.performInstallation();
72
+ }
73
+
74
+ // Step 4: Post-installation verification
75
+ await this.verifyInstallation();
76
+
77
+ // Step 5: Print summary
78
+ this.printSummary();
79
+
80
+ return this.results;
81
+ } catch (error) {
82
+ console.error('�?Enhanced installation failed:', error.message);
83
+ this.results.errors.push(error.message);
84
+ return this.results;
85
+ }
86
+ }
87
+
88
+ /**
89
+ * Pre-installation cache cleaning
90
+ */
91
+ async preInstallCacheClean(config) {
92
+ console.log('🧹 Pre-installation Cache Cleaning...\n');
93
+
94
+ const startTime = Date.now();
95
+
96
+ try {
97
+ // Clean caches before installation
98
+ const cacheResults = await this.cacheCleaner.cleanAllCaches(config);
99
+
100
+ const endTime = Date.now();
101
+ const duration = endTime - startTime;
102
+
103
+ this.results.cacheCleaning = {
104
+ success: true,
105
+ duration,
106
+ filesRemoved: cacheResults.filesRemoved,
107
+ directoriesRemoved: cacheResults.directoriesRemoved,
108
+ bytesFreed: cacheResults.bytesFreed,
109
+ errors: cacheResults.errors.length,
110
+ };
111
+
112
+ console.log(`�?Cache cleaning completed in ${duration}ms`);
113
+ console.log(
114
+ `📊 Removed ${cacheResults.filesRemoved} files, freed ${this.formatBytes(cacheResults.bytesFreed)}\n`,
115
+ );
116
+ } catch (error) {
117
+ console.error('�?Cache cleaning failed:', error.message);
118
+ this.results.cacheCleaning = {
119
+ success: false,
120
+ error: error.message,
121
+ };
122
+
123
+ if (!this.options.force) {
124
+ throw new Error(`Cache cleaning failed: ${error.message}`);
125
+ }
126
+
127
+ console.log(
128
+ '⚠️ Continuing installation despite cache cleaning errors...\n',
129
+ );
130
+ }
131
+ }
132
+
133
+ /**
134
+ * Scan system and prepare for installation
135
+ */
136
+ async scanAndPrepare() {
137
+ console.log('🔍 Scanning System for Installation...\n');
138
+
139
+ try {
140
+ // Check system requirements
141
+ await this.checkSystemRequirements();
142
+
143
+ // Scan for existing CLI tools
144
+ const scanResult = await this.baseInstaller.scanCLI();
145
+
146
+ console.log('�?System scan completed');
147
+ console.log(
148
+ `📊 Found ${Object.keys(scanResult.available).length} available CLI tools`,
149
+ );
150
+ console.log(
151
+ `📊 Missing ${Object.keys(scanResult.missing).length} CLI tools\n`,
152
+ );
153
+
154
+ this.results.scan = scanResult;
155
+ } catch (error) {
156
+ console.error('�?System scan failed:', error.message);
157
+ throw error;
158
+ }
159
+ }
160
+
161
+ /**
162
+ * Perform the actual installation
163
+ */
164
+ async performInstallation() {
165
+ console.log('📦 Performing Installation...\n');
166
+
167
+ try {
168
+ // Interactive tool selection would go here
169
+ // For now, we'll use a simple approach
170
+ const missingTools = Object.keys(this.results.scan.missing);
171
+
172
+ if (missingTools.length === 0) {
173
+ console.log('ℹ️ All CLI tools are already installed');
174
+ this.results.installation = {
175
+ success: true,
176
+ installed: [],
177
+ message: 'No tools needed installation',
178
+ };
179
+ return;
180
+ }
181
+
182
+ console.log(`📦 Installing ${missingTools.length} CLI tools...`);
183
+
184
+ // Install missing tools
185
+ const installResult = await this.baseInstaller.installTools(
186
+ missingTools,
187
+ this.results.scan.missing,
188
+ );
189
+
190
+ this.results.installation = {
191
+ success: true,
192
+ installed: missingTools,
193
+ result: installResult,
194
+ };
195
+
196
+ console.log('�?Installation completed');
197
+ } catch (error) {
198
+ console.error('�?Installation failed:', error.message);
199
+ this.results.installation = {
200
+ success: false,
201
+ error: error.message,
202
+ };
203
+ throw error;
204
+ }
205
+ }
206
+
207
+ /**
208
+ * Post-installation verification
209
+ */
210
+ async verifyInstallation() {
211
+ console.log('\n�?Post-installation Verification...');
212
+
213
+ try {
214
+ // Verify installation was successful
215
+ const postScan = await this.baseInstaller.scanCLI();
216
+
217
+ const verificationResults = {
218
+ beforeCount: Object.keys(this.results.scan.available).length,
219
+ afterCount: Object.keys(postScan.available).length,
220
+ newlyInstalled: [],
221
+ };
222
+
223
+ // Find newly installed tools
224
+ for (const tool of Object.keys(postScan.available)) {
225
+ if (!this.results.scan.available[tool]) {
226
+ verificationResults.newlyInstalled.push(tool);
227
+ }
228
+ }
229
+
230
+ this.results.verification = verificationResults;
231
+
232
+ console.log(`📊 CLI tools before: ${verificationResults.beforeCount}`);
233
+ console.log(`📊 CLI tools after: ${verificationResults.afterCount}`);
234
+ console.log(
235
+ `📊 Newly installed: ${verificationResults.newlyInstalled.length}`,
236
+ );
237
+
238
+ if (verificationResults.newlyInstalled.length > 0) {
239
+ console.log(
240
+ `�?Successfully installed: ${verificationResults.newlyInstalled.join(', ')}`,
241
+ );
242
+ }
243
+
244
+ console.log('�?Installation verification completed\n');
245
+ } catch (error) {
246
+ console.error('�?Verification failed:', error.message);
247
+ this.results.errors.push(`Verification: ${error.message}`);
248
+ }
249
+ }
250
+
251
+ /**
252
+ * Check system requirements
253
+ */
254
+ async checkSystemRequirements() {
255
+ console.log('🔧 Checking System Requirements...');
256
+
257
+ // Check Node.js version
258
+ const nodeVersion = process.version;
259
+ const majorVersion = parseInt(nodeVersion.slice(1).split('.')[0]);
260
+
261
+ if (majorVersion < 14) {
262
+ throw new Error(
263
+ `Node.js version ${nodeVersion} is not supported. Please use Node.js 14 or higher.`,
264
+ );
265
+ }
266
+
267
+ console.log(` �?Node.js: ${nodeVersion}`);
268
+
269
+ // Check npm availability
270
+ try {
271
+ const { spawnSync } = require('child_process');
272
+ const npmResult = spawnSync('npm', ['--version'], {
273
+ encoding: 'utf8',
274
+ shell: true,
275
+ });
276
+
277
+ if (npmResult.status === 0) {
278
+ console.log(` �?npm: ${npmResult.stdout.trim()}`);
279
+ } else {
280
+ throw new Error('npm is not available');
281
+ }
282
+ } catch (error) {
283
+ throw new Error('npm is required but not found');
284
+ }
285
+
286
+ // Check available disk space (basic check)
287
+ const homeDir = os.homedir();
288
+ try {
289
+ const stats = fs.statSync(homeDir);
290
+ console.log(` �?Home directory accessible: ${homeDir}`);
291
+ } catch (error) {
292
+ throw new Error(`Cannot access home directory: ${homeDir}`);
293
+ }
294
+
295
+ console.log('�?System requirements check passed\n');
296
+ }
297
+
298
+ /**
299
+ * Create installation plan without executing
300
+ */
301
+ async createInstallationPlan() {
302
+ console.log('📋 Creating Installation Plan...\n');
303
+
304
+ const plan = {
305
+ cacheCleaning: {},
306
+ installation: {},
307
+ estimatedTime: 0,
308
+ estimatedSpace: 0,
309
+ };
310
+
311
+ try {
312
+ // Check what would be cleaned
313
+ const stigmergyDir = path.join(os.homedir(), '.stigmergy');
314
+ if (fs.existsSync(stigmergyDir)) {
315
+ const cacheSize = await this.calculateDirectorySize(stigmergyDir);
316
+ plan.cacheCleaning.stigmergyCache = {
317
+ path: stigmergyDir,
318
+ size: cacheSize,
319
+ wouldClean: this.options.cleanBeforeInstall,
320
+ };
321
+ plan.estimatedSpace += cacheSize;
322
+ }
323
+
324
+ // Scan for missing CLI tools
325
+ const scanResult = await this.baseInstaller.scanCLI();
326
+ const missingTools = Object.keys(scanResult.missing);
327
+
328
+ plan.installation = {
329
+ missingTools: missingTools,
330
+ toolCount: missingTools.length,
331
+ tools: missingTools.map((tool) => ({
332
+ name: scanResult.missing[tool].name,
333
+ installCommand: scanResult.missing[tool].install,
334
+ })),
335
+ };
336
+
337
+ // Estimate time (very rough estimate)
338
+ plan.estimatedTime = missingTools.length * 30000; // 30 seconds per tool
339
+
340
+ console.log('📊 Installation Plan Summary:');
341
+ console.log(
342
+ ` 🧹 Cache cleaning: ${this.options.cleanBeforeInstall ? 'Yes' : 'No'}`,
343
+ );
344
+ console.log(` 📦 Tools to install: ${missingTools.length}`);
345
+ console.log(
346
+ ` ⏱️ Estimated time: ${Math.ceil(plan.estimatedTime / 1000)} seconds`,
347
+ );
348
+ console.log(
349
+ ` 💾 Estimated space: ${this.formatBytes(plan.estimatedSpace)}`,
350
+ );
351
+
352
+ return plan;
353
+ } catch (error) {
354
+ console.error('�?Failed to create installation plan:', error.message);
355
+ throw error;
356
+ }
357
+ }
358
+
359
+ /**
360
+ * Quick cache clean only
361
+ */
362
+ async quickCacheClean() {
363
+ console.log('�?Quick Cache Clean Only...\n');
364
+
365
+ try {
366
+ const results = await this.cacheCleaner.cleanAllCaches({
367
+ cleanStigmergy: false, // Don't clean main config
368
+ cleanNPX: true,
369
+ cleanNPM: false,
370
+ cleanCLI: false,
371
+ cleanTemp: true,
372
+ });
373
+
374
+ console.log('�?Quick cache clean completed');
375
+ console.log(
376
+ `📊 Removed ${results.filesRemoved} files, freed ${this.formatBytes(results.bytesFreed)}`,
377
+ );
378
+
379
+ return results;
380
+ } catch (error) {
381
+ console.error('�?Quick cache clean failed:', error.message);
382
+ throw error;
383
+ }
384
+ }
385
+
386
+ /**
387
+ * Helper methods
388
+ */
389
+ async calculateDirectorySize(dirPath) {
390
+ let totalSize = 0;
391
+
392
+ try {
393
+ const items = fs.readdirSync(dirPath, { withFileTypes: true });
394
+
395
+ for (const item of items) {
396
+ const fullPath = path.join(dirPath, item.name);
397
+
398
+ if (item.isDirectory()) {
399
+ totalSize += await this.calculateDirectorySize(fullPath);
400
+ } else {
401
+ try {
402
+ const stat = fs.statSync(fullPath);
403
+ totalSize += stat.size;
404
+ } catch (error) {
405
+ // Skip files we can't stat
406
+ }
407
+ }
408
+ }
409
+ } catch (error) {
410
+ // Return 0 for directories we can't read
411
+ }
412
+
413
+ return totalSize;
414
+ }
415
+
416
+ formatBytes(bytes) {
417
+ const sizes = ['Bytes', 'KB', 'MB', 'GB'];
418
+ if (bytes === 0) return '0 Bytes';
419
+ const i = Math.floor(Math.log(bytes) / Math.log(1024));
420
+ return Math.round((bytes / Math.pow(1024, i)) * 100) / 100 + ' ' + sizes[i];
421
+ }
422
+
423
+ printSummary() {
424
+ console.log('\n📊 ENHANCED INSTALLATION SUMMARY:');
425
+ console.log('='.repeat(50));
426
+
427
+ if (this.options.dryRun) {
428
+ console.log('🔍 DRY RUN MODE - No actual changes were made');
429
+ }
430
+
431
+ // Cache cleaning summary
432
+ if (this.results.cacheCleaning.success) {
433
+ console.log('🧹 Cache Cleaning: SUCCESS');
434
+ console.log(` Duration: ${this.results.cacheCleaning.duration}ms`);
435
+ console.log(
436
+ ` Files removed: ${this.results.cacheCleaning.filesRemoved}`,
437
+ );
438
+ console.log(
439
+ ` Space freed: ${this.formatBytes(this.results.cacheCleaning.bytesFreed)}`,
440
+ );
441
+ } else if (this.results.cacheCleaning.error) {
442
+ console.log(`🧹 Cache Cleaning: �?${this.results.cacheCleaning.error}`);
443
+ }
444
+
445
+ // Installation summary
446
+ if (this.results.installation.success) {
447
+ console.log('📦 Installation: SUCCESS');
448
+ if (this.results.installation.installed.length > 0) {
449
+ console.log(
450
+ ` Installed: ${this.results.installation.installed.join(', ')}`,
451
+ );
452
+ } else {
453
+ console.log(` Message: ${this.results.installation.message}`);
454
+ }
455
+ } else if (this.results.installation.error) {
456
+ console.log(`📦 Installation: �?${this.results.installation.error}`);
457
+ }
458
+
459
+ // Verification summary
460
+ if (this.results.verification) {
461
+ console.log('Verification: SUCCESS');
462
+ console.log(
463
+ ` Newly installed: ${this.results.verification.newlyInstalled.length} tools`,
464
+ );
465
+ }
466
+
467
+ // Errors
468
+ if (this.results.errors.length > 0) {
469
+ console.log(`\n�?Errors encountered: ${this.results.errors.length}`);
470
+ this.results.errors.forEach((error) => {
471
+ console.log(` - ${error}`);
472
+ });
473
+ }
474
+
475
+ console.log('\n🎉 Enhanced installation completed!');
476
+ }
477
+ }
478
+
479
+ module.exports = EnhancedInstaller;