-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall_performance_optimizations.py
More file actions
executable file
·859 lines (699 loc) · 32.2 KB
/
Copy pathinstall_performance_optimizations.py
File metadata and controls
executable file
·859 lines (699 loc) · 32.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
#!/usr/bin/env python3
"""
Performance Optimization Installer for NeuralSync v2
Comprehensive installer for all performance enhancements and monitoring
"""
import os
import sys
import shutil
import subprocess
import logging
import time
import json
from typing import Dict, Any, Optional, List, Tuple
from pathlib import Path
import platform
# Configure logging
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(levelname)s - %(message)s'
)
logger = logging.getLogger(__name__)
class PerformanceOptimizationInstaller:
"""Comprehensive installer for NeuralSync v2 performance optimizations"""
def __init__(self, install_dir: str = None, sudo_password: str = None):
self.system_type = platform.system().lower()
self.python_executable = sys.executable
# Installation paths
if install_dir is None:
if self.system_type == 'darwin':
install_dir = '/usr/local/bin'
else:
install_dir = '/usr/local/bin'
self.install_dir = Path(install_dir)
self.source_dir = Path(__file__).parent
self.config_dir = Path.home() / '.neuralsync'
self.cache_dir = Path('/tmp/neuralsync_cache')
# Sudo password for system operations
self.sudo_password = sudo_password
self.sudo_cached = False
# Installation components
self.components = {
'core_optimizations': {
'description': 'Core performance optimization modules',
'files': [
'intelligent_cache.py',
'async_network.py',
'context_prewarmer.py',
'fast_recall.py',
'lazy_loader.py',
'cli_performance_integration.py',
'optimized_server.py'
],
'required': True
},
'optimized_cli': {
'description': 'Optimized CLI wrapper (nswrap)',
'files': ['nswrap_optimized'],
'executable': True,
'required': True
},
'performance_monitoring': {
'description': 'Enhanced performance monitoring',
'files': ['performance_monitor.py'],
'required': False
},
'dependencies': {
'description': 'Performance optimization dependencies',
'packages': [
'aiohttp>=3.8.0',
'lz4>=4.0.0',
'psutil>=5.9.0',
'numpy>=1.21.0',
'httptools>=0.4.0'
],
'required': True
},
'system_configs': {
'description': 'System-level performance configurations',
'configs': [
('NS_FAST_MODE', '1'),
('NS_PRELOAD', '1'),
('NS_MAX_WAIT_MS', '800'),
('NS_LOADING_MODE', 'adaptive')
],
'required': False
}
}
# Installation status
self.installation_log = []
self.errors = []
self.warnings = []
logger.info("PerformanceOptimizationInstaller initialized")
def run_with_sudo(self, command: List[str], capture_output: bool = True) -> subprocess.CompletedProcess:
"""Run command with sudo, using cached password if available"""
if self.system_type == 'darwin' or self.system_type == 'linux':
if not self.sudo_cached and self.sudo_password:
# Cache sudo password
cache_cmd = ['sudo', '-S', 'true']
result = subprocess.run(
cache_cmd,
input=f"{self.sudo_password}\n",
text=True,
capture_output=True
)
if result.returncode == 0:
self.sudo_cached = True
logger.info("Sudo access cached successfully")
else:
raise RuntimeError(f"Sudo authentication failed: {result.stderr}")
sudo_command = ['sudo'] + command
else:
sudo_command = command
return subprocess.run(sudo_command, capture_output=capture_output, text=True)
def check_system_requirements(self) -> Dict[str, Any]:
"""Check system requirements for performance optimizations"""
logger.info("Checking system requirements...")
requirements = {
'python_version': {
'required': '3.8.0',
'current': f"{sys.version_info.major}.{sys.version_info.minor}.{sys.version_info.micro}",
'satisfied': sys.version_info >= (3, 8, 0)
},
'disk_space': {
'required_mb': 100,
'available_mb': 0,
'satisfied': False
},
'memory': {
'required_mb': 512,
'available_mb': 0,
'satisfied': False
},
'network_access': {
'required': True,
'satisfied': False
}
}
# Check disk space
try:
disk_usage = shutil.disk_usage(self.install_dir.parent)
available_mb = disk_usage.free // (1024 * 1024)
requirements['disk_space']['available_mb'] = available_mb
requirements['disk_space']['satisfied'] = available_mb >= requirements['disk_space']['required_mb']
except Exception as e:
logger.warning(f"Could not check disk space: {e}")
# Check memory
try:
import psutil
memory = psutil.virtual_memory()
available_mb = memory.available // (1024 * 1024)
requirements['memory']['available_mb'] = available_mb
requirements['memory']['satisfied'] = available_mb >= requirements['memory']['required_mb']
except ImportError:
logger.warning("psutil not available for memory check")
requirements['memory']['satisfied'] = True # Assume satisfied
# Check network access
try:
import urllib.request
urllib.request.urlopen('https://pypi.org', timeout=5)
requirements['network_access']['satisfied'] = True
except Exception:
logger.warning("Network access check failed")
# Log results
for requirement, details in requirements.items():
if details['satisfied']:
logger.info(f"✓ {requirement}: {details.get('current', 'OK')}")
else:
logger.error(f"✗ {requirement}: {details}")
self.errors.append(f"System requirement not met: {requirement}")
return requirements
def install_dependencies(self) -> bool:
"""Install required Python dependencies"""
logger.info("Installing performance optimization dependencies...")
packages = self.components['dependencies']['packages']
try:
# Upgrade pip first
subprocess.check_call([
self.python_executable, '-m', 'pip', 'install', '--upgrade', 'pip'
])
# Install packages
install_cmd = [
self.python_executable, '-m', 'pip', 'install', '--upgrade'
] + packages
result = subprocess.run(install_cmd, capture_output=True, text=True)
if result.returncode == 0:
logger.info("Dependencies installed successfully")
self.installation_log.append("Dependencies installed")
return True
else:
logger.error(f"Dependency installation failed: {result.stderr}")
self.errors.append(f"Dependency installation failed: {result.stderr}")
return False
except Exception as e:
logger.error(f"Dependency installation error: {e}")
self.errors.append(f"Dependency installation error: {e}")
return False
def install_core_optimizations(self) -> bool:
"""Install core optimization modules"""
logger.info("Installing core performance optimization modules...")
try:
# Ensure neuralsync module directory exists
neuralsync_dir = self.source_dir / 'neuralsync'
if not neuralsync_dir.exists():
self.errors.append("Source neuralsync directory not found")
return False
# Files are already in place, just validate they exist
core_files = self.components['core_optimizations']['files']
missing_files = []
for filename in core_files:
file_path = neuralsync_dir / filename
if not file_path.exists():
missing_files.append(filename)
if missing_files:
self.errors.append(f"Missing core optimization files: {missing_files}")
return False
logger.info("Core optimization modules validated")
self.installation_log.append("Core optimizations validated")
return True
except Exception as e:
logger.error(f"Core optimization installation error: {e}")
self.errors.append(f"Core optimization installation error: {e}")
return False
def install_optimized_cli(self) -> bool:
"""Install optimized CLI wrapper"""
logger.info("Installing optimized CLI wrapper...")
try:
source_file = self.source_dir / 'nswrap_optimized'
target_file = self.install_dir / 'nswrap'
if not source_file.exists():
self.errors.append("nswrap_optimized source file not found")
return False
# Create install directory if it doesn't exist
self.install_dir.mkdir(parents=True, exist_ok=True)
# Copy file with sudo if needed
try:
if self.install_dir.is_dir() and os.access(self.install_dir, os.W_OK):
# Directory is writable
shutil.copy2(source_file, target_file)
os.chmod(target_file, 0o755)
else:
# Need sudo
result = self.run_with_sudo(['cp', str(source_file), str(target_file)])
if result.returncode != 0:
raise RuntimeError(f"Copy failed: {result.stderr}")
# Make executable
result = self.run_with_sudo(['chmod', '755', str(target_file)])
if result.returncode != 0:
logger.warning(f"Could not make executable: {result.stderr}")
logger.info(f"Optimized CLI installed to {target_file}")
self.installation_log.append(f"CLI installed to {target_file}")
# Create backup of original nswrap if it exists
original_nswrap = self.source_dir / 'nswrap'
if original_nswrap.exists():
backup_file = self.source_dir / 'nswrap_original'
if not backup_file.exists():
shutil.copy2(original_nswrap, backup_file)
logger.info("Original nswrap backed up")
return True
except Exception as e:
logger.error(f"CLI installation failed: {e}")
self.errors.append(f"CLI installation failed: {e}")
return False
except Exception as e:
logger.error(f"CLI installation error: {e}")
self.errors.append(f"CLI installation error: {e}")
return False
def setup_configuration(self) -> bool:
"""Setup configuration files and environment"""
logger.info("Setting up performance configuration...")
try:
# Create config directory
self.config_dir.mkdir(parents=True, exist_ok=True)
# Create cache directory
self.cache_dir.mkdir(parents=True, exist_ok=True)
# Create performance configuration file
config_file = self.config_dir / 'performance.json'
performance_config = {
'version': '2.0.0',
'optimizations_enabled': True,
'fast_mode': True,
'preloading_enabled': True,
'max_wait_ms': 800,
'loading_mode': 'adaptive',
'cache_settings': {
'persona_ttl_ms': 600000,
'memory_ttl_ms': 300000,
'context_ttl_ms': 180000,
'max_cache_size_mb': 256
},
'performance_thresholds': {
'excellent_ms': 200,
'good_ms': 500,
'acceptable_ms': 1000
},
'installed_components': list(self.components.keys())
}
with open(config_file, 'w') as f:
json.dump(performance_config, f, indent=2)
logger.info(f"Performance configuration created: {config_file}")
self.installation_log.append("Configuration files created")
# Setup shell environment suggestions
shell_config = self._generate_shell_config()
shell_config_file = self.config_dir / 'shell_config.sh'
with open(shell_config_file, 'w') as f:
f.write(shell_config)
logger.info(f"Shell configuration generated: {shell_config_file}")
self.installation_log.append("Shell configuration generated")
return True
except Exception as e:
logger.error(f"Configuration setup error: {e}")
self.errors.append(f"Configuration setup error: {e}")
return False
def _generate_shell_config(self) -> str:
"""Generate shell configuration for performance optimizations"""
config_lines = [
"#!/bin/bash",
"# NeuralSync v2 Performance Optimization Configuration",
"# Source this file in your shell profile (.bashrc, .zshrc, etc.)",
"",
"# Performance optimization environment variables",
]
for key, value in self.components['system_configs']['configs']:
config_lines.append(f"export {key}={value}")
config_lines.extend([
"",
"# Additional optimization settings",
"export NS_CACHE_DIR=/tmp/neuralsync_cache",
f"export NS_CONFIG_DIR={self.config_dir}",
"export NS_DEBUG_PERF=0 # Set to 1 for debug output",
"",
"# Ensure nswrap is in PATH",
f"export PATH=\"{self.install_dir}:$PATH\"",
"",
"# Optional: Create aliases for common operations",
"alias ns-stats='python3 -c \"from neuralsync.cli_performance_integration import get_performance_integration; import json; print(json.dumps(get_performance_integration().get_performance_summary(), indent=2))\"'",
"alias ns-cache-clear='python3 -c \"from neuralsync.intelligent_cache import get_neuralsync_cache; import asyncio; asyncio.run(get_neuralsync_cache().persona_cache.clear())\"'",
"",
"echo '✅ NeuralSync v2 Performance Optimizations Loaded'"
])
return "\n".join(config_lines)
def validate_installation(self) -> Dict[str, bool]:
"""Validate that all components are properly installed"""
logger.info("Validating installation...")
validation_results = {}
# Check CLI wrapper
nswrap_path = self.install_dir / 'nswrap'
validation_results['cli_wrapper'] = nswrap_path.exists() and os.access(nswrap_path, os.X_OK)
# Check core modules
core_modules_valid = True
try:
import neuralsync.intelligent_cache
import neuralsync.async_network
import neuralsync.context_prewarmer
import neuralsync.fast_recall
import neuralsync.lazy_loader
import neuralsync.cli_performance_integration
except ImportError as e:
core_modules_valid = False
self.errors.append(f"Module import failed: {e}")
validation_results['core_modules'] = core_modules_valid
# Check dependencies
dependencies_valid = True
try:
import aiohttp
import lz4
import psutil
import numpy
except ImportError as e:
dependencies_valid = False
self.errors.append(f"Dependency import failed: {e}")
validation_results['dependencies'] = dependencies_valid
# Check configuration
config_file = self.config_dir / 'performance.json'
validation_results['configuration'] = config_file.exists()
# Test basic functionality
functionality_valid = True
try:
# Quick functionality test
result = subprocess.run([
str(nswrap_path), '--', 'echo', 'test'
], capture_output=True, text=True, timeout=5)
if result.returncode != 0 or 'test' not in result.stdout:
functionality_valid = False
self.errors.append(f"Functionality test failed: {result.stderr}")
except Exception as e:
functionality_valid = False
self.errors.append(f"Functionality test error: {e}")
validation_results['functionality'] = functionality_valid
# Log validation results
for component, is_valid in validation_results.items():
if is_valid:
logger.info(f"✓ {component} validation passed")
else:
logger.error(f"✗ {component} validation failed")
return validation_results
def create_uninstaller(self) -> bool:
"""Create uninstaller script"""
logger.info("Creating uninstaller...")
try:
uninstaller_content = f'''#!/usr/bin/env python3
"""
NeuralSync v2 Performance Optimizations Uninstaller
Auto-generated uninstaller script
"""
import os
import shutil
import subprocess
from pathlib import Path
def uninstall():
print("🗑️ Uninstalling NeuralSync v2 Performance Optimizations...")
items_removed = []
# Remove CLI wrapper
cli_file = Path("{self.install_dir}/nswrap")
if cli_file.exists():
try:
if os.access(cli_file.parent, os.W_OK):
cli_file.unlink()
else:
subprocess.run(["sudo", "rm", str(cli_file)], check=True)
items_removed.append(str(cli_file))
except Exception as e:
print(f"Warning: Could not remove {{cli_file}}: {{e}}")
# Remove configuration directory
config_dir = Path("{self.config_dir}")
if config_dir.exists():
try:
shutil.rmtree(config_dir)
items_removed.append(str(config_dir))
except Exception as e:
print(f"Warning: Could not remove {{config_dir}}: {{e}}")
# Remove cache directory
cache_dir = Path("{self.cache_dir}")
if cache_dir.exists():
try:
shutil.rmtree(cache_dir)
items_removed.append(str(cache_dir))
except Exception as e:
print(f"Warning: Could not remove {{cache_dir}}: {{e}}")
# Restore original nswrap if backup exists
original_backup = Path("{self.source_dir}/nswrap_original")
original_nswrap = Path("{self.source_dir}/nswrap")
if original_backup.exists():
try:
shutil.copy2(original_backup, original_nswrap)
original_backup.unlink()
items_removed.append("Restored original nswrap")
except Exception as e:
print(f"Warning: Could not restore original nswrap: {{e}}")
print(f"✅ Uninstallation complete. Removed {{len(items_removed)}} items:")
for item in items_removed:
print(f" - {{item}}")
print("\\n📝 Manual cleanup needed:")
print(" - Remove environment variables from shell profile")
print(" - Uninstall Python dependencies if no longer needed:")
print(" pip uninstall aiohttp lz4 psutil httptools")
if __name__ == "__main__":
uninstall()
'''
uninstaller_path = self.source_dir / 'uninstall_performance_optimizations.py'
with open(uninstaller_path, 'w') as f:
f.write(uninstaller_content)
os.chmod(uninstaller_path, 0o755)
logger.info(f"Uninstaller created: {uninstaller_path}")
self.installation_log.append("Uninstaller created")
return True
except Exception as e:
logger.error(f"Uninstaller creation failed: {e}")
self.warnings.append(f"Uninstaller creation failed: {e}")
return False
def run_performance_test(self) -> Dict[str, Any]:
"""Run quick performance test to verify optimizations"""
logger.info("Running performance validation test...")
test_results = {
'cli_response_times': [],
'cache_performance': {},
'overall_health': 'unknown'
}
try:
nswrap_path = self.install_dir / 'nswrap'
# Test CLI response times
test_commands = [
['echo', 'hello'],
['pwd'],
['date']
]
for cmd in test_commands:
start_time = time.perf_counter()
result = subprocess.run([
str(nswrap_path), '--'
] + cmd, capture_output=True, text=True, timeout=5)
response_time_ms = (time.perf_counter() - start_time) * 1000
test_results['cli_response_times'].append({
'command': ' '.join(cmd),
'response_time_ms': response_time_ms,
'success': result.returncode == 0
})
# Calculate average response time
successful_times = [
t['response_time_ms'] for t in test_results['cli_response_times']
if t['success']
]
if successful_times:
avg_time = sum(successful_times) / len(successful_times)
if avg_time < 200:
test_results['overall_health'] = 'excellent'
elif avg_time < 500:
test_results['overall_health'] = 'good'
elif avg_time < 1000:
test_results['overall_health'] = 'acceptable'
else:
test_results['overall_health'] = 'needs_improvement'
logger.info(f"Average CLI response time: {avg_time:.1f}ms ({test_results['overall_health']})")
return test_results
except Exception as e:
logger.error(f"Performance test failed: {e}")
test_results['error'] = str(e)
return test_results
def install(self, skip_sudo_prompt: bool = False) -> bool:
"""Run complete installation process"""
logger.info("🚀 Starting NeuralSync v2 Performance Optimization Installation")
# Request sudo password if needed
if not skip_sudo_prompt and self.sudo_password is None and self.system_type in ['darwin', 'linux']:
import getpass
try:
self.sudo_password = getpass.getpass("Enter sudo password (for system installation): ")
except KeyboardInterrupt:
logger.info("Installation cancelled by user")
return False
success = True
# Step 1: Check system requirements
logger.info("Step 1/7: Checking system requirements...")
requirements = self.check_system_requirements()
if not all(req['satisfied'] for req in requirements.values()):
logger.error("System requirements not met")
success = False
# Step 2: Install dependencies
if success:
logger.info("Step 2/7: Installing dependencies...")
if not self.install_dependencies():
success = False
# Step 3: Install core optimizations
if success:
logger.info("Step 3/7: Validating core optimizations...")
if not self.install_core_optimizations():
success = False
# Step 4: Install CLI wrapper
if success:
logger.info("Step 4/7: Installing optimized CLI...")
if not self.install_optimized_cli():
success = False
# Step 5: Setup configuration
if success:
logger.info("Step 5/7: Setting up configuration...")
if not self.setup_configuration():
success = False
# Step 6: Validate installation
if success:
logger.info("Step 6/7: Validating installation...")
validation_results = self.validate_installation()
if not all(validation_results.values()):
logger.warning("Some validation checks failed, but continuing...")
for component, valid in validation_results.items():
if not valid:
self.warnings.append(f"{component} validation failed")
# Step 7: Create uninstaller and run tests
logger.info("Step 7/7: Finalizing installation...")
self.create_uninstaller()
if success:
test_results = self.run_performance_test()
# Generate installation report
self._generate_installation_report(success, test_results, validation_results)
return success
def _generate_installation_report(self, success: bool, test_results: Dict[str, Any], validation_results: Dict[str, bool]):
"""Generate comprehensive installation report"""
report_file = self.config_dir / 'installation_report.json'
report = {
'installation_timestamp': time.time(),
'installation_success': success,
'system_info': {
'platform': platform.platform(),
'python_version': sys.version,
'install_dir': str(self.install_dir),
'config_dir': str(self.config_dir)
},
'components_installed': list(self.components.keys()),
'installation_log': self.installation_log,
'errors': self.errors,
'warnings': self.warnings,
'validation_results': validation_results,
'performance_test': test_results,
'next_steps': self._generate_next_steps()
}
try:
with open(report_file, 'w') as f:
json.dump(report, f, indent=2)
logger.info(f"Installation report saved: {report_file}")
except Exception as e:
logger.warning(f"Could not save installation report: {e}")
# Print summary
self._print_installation_summary(success, test_results)
def _generate_next_steps(self) -> List[str]:
"""Generate next steps for user"""
steps = [
f"Source the shell configuration: source {self.config_dir}/shell_config.sh",
"Add the shell configuration to your profile (.bashrc, .zshrc, etc.)",
"Test the installation with: nswrap -- echo 'Hello NeuralSync v2!'",
"Monitor performance with: ns-stats (after sourcing shell config)",
f"View detailed configuration at: {self.config_dir}/performance.json"
]
if self.errors:
steps.append("Review and resolve any installation errors listed above")
if self.warnings:
steps.append("Review installation warnings for potential improvements")
return steps
def _print_installation_summary(self, success: bool, test_results: Dict[str, Any]):
"""Print installation summary"""
print("\n" + "="*70)
print("🎯 NEURALSYNC v2 PERFORMANCE OPTIMIZATION INSTALLATION SUMMARY")
print("="*70)
if success:
print("✅ Installation completed successfully!")
else:
print("❌ Installation completed with errors")
print(f"\n📊 INSTALLATION STATISTICS:")
print(f" Components installed: {len(self.installation_log)}")
print(f" Errors encountered: {len(self.errors)}")
print(f" Warnings: {len(self.warnings)}")
if test_results.get('cli_response_times'):
successful_times = [
t['response_time_ms'] for t in test_results['cli_response_times']
if t['success']
]
if successful_times:
avg_time = sum(successful_times) / len(successful_times)
print(f" Average CLI response: {avg_time:.1f}ms ({test_results.get('overall_health', 'unknown')})")
if self.errors:
print(f"\n❌ ERRORS:")
for error in self.errors:
print(f" • {error}")
if self.warnings:
print(f"\n⚠️ WARNINGS:")
for warning in self.warnings:
print(f" • {warning}")
print(f"\n📁 INSTALLATION PATHS:")
print(f" CLI Wrapper: {self.install_dir}/nswrap")
print(f" Configuration: {self.config_dir}")
print(f" Cache Directory: {self.cache_dir}")
print(f"\n🚀 NEXT STEPS:")
for i, step in enumerate(self._generate_next_steps(), 1):
print(f" {i}. {step}")
print(f"\n🗑️ TO UNINSTALL:")
print(f" Run: python3 {self.source_dir}/uninstall_performance_optimizations.py")
print("\n" + "="*70)
if success and test_results.get('overall_health') in ['excellent', 'good']:
print("🎉 NeuralSync v2 Performance Optimizations are ready!")
print(" Your CLI should now respond in sub-second times.")
elif success:
print("✅ Installation complete - some performance tuning may be needed.")
else:
print("❌ Installation had issues - please review errors and try again.")
print("="*70)
def main():
"""Main installer function"""
import argparse
parser = argparse.ArgumentParser(
description="Install NeuralSync v2 Performance Optimizations"
)
parser.add_argument(
'--install-dir',
default=None,
help='Installation directory for CLI tools (default: /usr/local/bin)'
)
parser.add_argument(
'--skip-sudo',
action='store_true',
help='Skip sudo password prompt (may cause installation failures)'
)
parser.add_argument(
'--verbose',
action='store_true',
help='Enable verbose logging'
)
args = parser.parse_args()
if args.verbose:
logging.getLogger().setLevel(logging.DEBUG)
installer = PerformanceOptimizationInstaller(
install_dir=args.install_dir
)
try:
success = installer.install(skip_sudo_prompt=args.skip_sudo)
sys.exit(0 if success else 1)
except KeyboardInterrupt:
print("\n❌ Installation cancelled by user")
sys.exit(1)
except Exception as e:
logger.error(f"Installation failed with unexpected error: {e}")
sys.exit(1)
if __name__ == "__main__":
main()