Coverage for /Users/les/Projects/crackerjack/crackerjack/cli/facade.py: 0%

56 statements  

« prev     ^ index     » next       coverage.py v7.10.6, created at 2025-09-03 15:39 -0700

1import asyncio 

2from pathlib import Path 

3 

4from rich.console import Console 

5 

6from crackerjack.core.workflow_orchestrator import WorkflowOrchestrator 

7from crackerjack.models.protocols import OptionsProtocol 

8 

9 

10class CrackerjackCLIFacade: 

11 def __init__( 

12 self, 

13 console: Console | None = None, 

14 pkg_path: Path | None = None, 

15 ) -> None: 

16 self.console = console or Console(force_terminal=True) 

17 self.pkg_path = pkg_path or Path.cwd() 

18 self.orchestrator = WorkflowOrchestrator( 

19 console=self.console, 

20 pkg_path=self.pkg_path, 

21 ) 

22 

23 def process(self, options: OptionsProtocol) -> None: 

24 try: 

25 if self._should_handle_special_mode(options): 

26 self._handle_special_modes(options) 

27 return 

28 success = asyncio.run(self.orchestrator.run_complete_workflow(options)) 

29 if not success: 

30 self.console.print("[red]❌ Workflow completed with errors[/ red]") 

31 else: 

32 self.console.print( 

33 "[green]🎉 Workflow completed successfully ![/ green]" 

34 ) 

35 except KeyboardInterrupt: 

36 self.console.print("\n[yellow]⏹️ Operation cancelled by user[/ yellow]") 

37 raise SystemExit(130) 

38 except Exception as e: 

39 self.console.print(f"[red]💥 Unexpected error: {e}[/ red]") 

40 if options.verbose: 

41 import traceback 

42 

43 self.console.print(f"[dim]{traceback.format_exc()}[/ dim]") 

44 raise SystemExit(1) 

45 

46 async def process_async(self, options: OptionsProtocol) -> None: 

47 await asyncio.to_thread(self.process, options) 

48 

49 def _should_handle_special_mode(self, options: OptionsProtocol) -> bool: 

50 return ( 

51 getattr(options, "start_mcp_server", False) 

52 or getattr(options, "enterprise_batch", False) 

53 or getattr(options, "monitor_dashboard", False) 

54 ) 

55 

56 def _handle_special_modes(self, options: OptionsProtocol) -> None: 

57 if getattr(options, "start_mcp_server", False): 

58 self._start_mcp_server() 

59 elif getattr(options, "enterprise_batch", False): 

60 self._handle_enterprise_batch(options) 

61 elif getattr(options, "monitor_dashboard", False): 

62 self._handle_monitor_dashboard(options) 

63 

64 def _start_mcp_server(self) -> None: 

65 try: 

66 from crackerjack.mcp.server import main as start_mcp_main 

67 

68 self.console.print( 

69 "[bold cyan]🤖 Starting Crackerjack MCP Server...[/ bold cyan]", 

70 ) 

71 start_mcp_main(str(self.pkg_path)) 

72 except ImportError: 

73 self.console.print( 

74 "[red]❌ MCP server requires additional dependencies[/ red]", 

75 ) 

76 self.console.print("[yellow]Install with: uv sync --group mcp[/ yellow]") 

77 raise SystemExit(1) 

78 except Exception as e: 

79 self.console.print(f"[red]❌ Failed to start MCP server: {e}[/ red]") 

80 raise SystemExit(1) 

81 

82 def _handle_enterprise_batch(self, options: OptionsProtocol) -> None: 

83 self.console.print( 

84 "[red]❌ Enterprise batch processing is not yet implemented[/ red]" 

85 ) 

86 raise SystemExit(1) 

87 

88 def _handle_monitor_dashboard(self, options: OptionsProtocol) -> None: 

89 self.console.print("[red]❌ Monitoring dashboard is not yet implemented[/ red]") 

90 raise SystemExit(1) 

91 

92 

93def create_crackerjack_runner( 

94 console: Console | None = None, 

95 pkg_path: Path | None = None, 

96) -> CrackerjackCLIFacade: 

97 return CrackerjackCLIFacade(console=console, pkg_path=pkg_path) 

98 

99 

100CrackerjackRunner = CrackerjackCLIFacade