2020 print_all_preferences ,
2121 format_preference_value
2222)
23+ from cortex .preflight_checker import PreflightChecker , format_report , export_report
2324
2425
2526class CortexCLI :
@@ -61,7 +62,11 @@ def _clear_line(self):
6162 sys .stdout .write ('\r \033 [K' )
6263 sys .stdout .flush ()
6364
64- def install (self , software : str , execute : bool = False , dry_run : bool = False ):
65+ def install (self , software : str , execute : bool = False , dry_run : bool = False , simulate : bool = False ):
66+ # Handle simulation mode first - no API key needed
67+ if simulate :
68+ return self ._run_simulation (software )
69+
6570 api_key = self ._get_api_key ()
6671 if not api_key :
6772 return 1
@@ -187,6 +192,30 @@ def progress_callback(current, total, step):
187192 history .update_installation (install_id , InstallationStatus .FAILED , str (e ))
188193 self ._print_error (f"Unexpected error: { str (e )} " )
189194 return 1
195+
196+ def _run_simulation (self , software : str ) -> int :
197+ """Run preflight simulation check for installation"""
198+ try :
199+ # Get API key for LLM-powered package info (optional)
200+ api_key = self ._get_api_key ()
201+ provider = self ._get_provider () if api_key else 'openai'
202+
203+ # Create checker with optional API key for enhanced accuracy
204+ checker = PreflightChecker (api_key = api_key , provider = provider )
205+ report = checker .run_all_checks (software )
206+
207+ # Print formatted report
208+ output = format_report (report , software )
209+ print (output )
210+
211+ # Return error code if blocking issues found
212+ if report .errors :
213+ return 1
214+ return 0
215+
216+ except Exception as e :
217+ self ._print_error (f"Simulation failed: { str (e )} " )
218+ return 1
190219
191220 def history (self , limit : int = 20 , status : Optional [str ] = None , show_id : Optional [str ] = None ):
192221 """Show installation history"""
@@ -496,6 +525,7 @@ def main():
496525Examples:
497526 cortex install docker
498527 cortex install docker --execute
528+ cortex install docker --simulate
499529 cortex install "python 3.11 with pip"
500530 cortex install nginx --dry-run
501531 cortex history
@@ -520,6 +550,7 @@ def main():
520550 install_parser .add_argument ('software' , type = str , help = 'Software to install (natural language)' )
521551 install_parser .add_argument ('--execute' , action = 'store_true' , help = 'Execute the generated commands' )
522552 install_parser .add_argument ('--dry-run' , action = 'store_true' , help = 'Show commands without executing' )
553+ install_parser .add_argument ('--simulate' , action = 'store_true' , help = 'Simulate installation without making changes' )
523554
524555 # History command
525556 history_parser = subparsers .add_parser ('history' , help = 'View installation history' )
@@ -556,7 +587,7 @@ def main():
556587
557588 try :
558589 if args .command == 'install' :
559- return cli .install (args .software , execute = args .execute , dry_run = args .dry_run )
590+ return cli .install (args .software , execute = args .execute , dry_run = args .dry_run , simulate = args . simulate )
560591 elif args .command == 'history' :
561592 return cli .history (limit = args .limit , status = args .status , show_id = args .show_id )
562593 elif args .command == 'rollback' :
0 commit comments