claude-mpm 3.7.4__py3-none-any.whl → 3.8.1__py3-none-any.whl
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.
- claude_mpm/VERSION +1 -1
- claude_mpm/agents/BASE_PM.md +0 -106
- claude_mpm/agents/INSTRUCTIONS.md +0 -78
- claude_mpm/agents/MEMORY.md +88 -0
- claude_mpm/agents/WORKFLOW.md +86 -0
- claude_mpm/agents/schema/agent_schema.json +1 -1
- claude_mpm/agents/templates/code_analyzer.json +26 -11
- claude_mpm/agents/templates/data_engineer.json +4 -7
- claude_mpm/agents/templates/documentation.json +2 -2
- claude_mpm/agents/templates/engineer.json +2 -2
- claude_mpm/agents/templates/ops.json +3 -8
- claude_mpm/agents/templates/qa.json +2 -3
- claude_mpm/agents/templates/research.json +2 -3
- claude_mpm/agents/templates/security.json +3 -6
- claude_mpm/agents/templates/ticketing.json +4 -9
- claude_mpm/agents/templates/version_control.json +3 -3
- claude_mpm/agents/templates/web_qa.json +4 -4
- claude_mpm/agents/templates/web_ui.json +4 -4
- claude_mpm/cli/__init__.py +2 -2
- claude_mpm/cli/commands/__init__.py +2 -1
- claude_mpm/cli/commands/agents.py +118 -1
- claude_mpm/cli/commands/tickets.py +596 -19
- claude_mpm/cli/parser.py +228 -5
- claude_mpm/config/__init__.py +30 -39
- claude_mpm/config/socketio_config.py +8 -5
- claude_mpm/constants.py +13 -0
- claude_mpm/core/__init__.py +8 -18
- claude_mpm/core/cache.py +596 -0
- claude_mpm/core/claude_runner.py +166 -622
- claude_mpm/core/config.py +5 -1
- claude_mpm/core/constants.py +339 -0
- claude_mpm/core/container.py +461 -22
- claude_mpm/core/exceptions.py +392 -0
- claude_mpm/core/framework_loader.py +208 -93
- claude_mpm/core/interactive_session.py +432 -0
- claude_mpm/core/interfaces.py +424 -0
- claude_mpm/core/lazy.py +467 -0
- claude_mpm/core/logging_config.py +444 -0
- claude_mpm/core/oneshot_session.py +465 -0
- claude_mpm/core/optimized_agent_loader.py +485 -0
- claude_mpm/core/optimized_startup.py +490 -0
- claude_mpm/core/service_registry.py +52 -26
- claude_mpm/core/socketio_pool.py +162 -5
- claude_mpm/core/types.py +292 -0
- claude_mpm/core/typing_utils.py +477 -0
- claude_mpm/dashboard/static/js/components/file-tool-tracker.js +46 -2
- claude_mpm/dashboard/templates/index.html +5 -5
- claude_mpm/hooks/claude_hooks/hook_handler.py +213 -99
- claude_mpm/init.py +2 -1
- claude_mpm/services/__init__.py +78 -14
- claude_mpm/services/agent/__init__.py +24 -0
- claude_mpm/services/agent/deployment.py +2548 -0
- claude_mpm/services/agent/management.py +598 -0
- claude_mpm/services/agent/registry.py +813 -0
- claude_mpm/services/agents/deployment/agent_deployment.py +592 -269
- claude_mpm/services/agents/deployment/async_agent_deployment.py +5 -1
- claude_mpm/services/agents/management/agent_capabilities_generator.py +21 -11
- claude_mpm/services/agents/memory/agent_memory_manager.py +156 -1
- claude_mpm/services/async_session_logger.py +8 -3
- claude_mpm/services/communication/__init__.py +21 -0
- claude_mpm/services/communication/socketio.py +1933 -0
- claude_mpm/services/communication/websocket.py +479 -0
- claude_mpm/services/core/__init__.py +123 -0
- claude_mpm/services/core/base.py +247 -0
- claude_mpm/services/core/interfaces.py +951 -0
- claude_mpm/services/framework_claude_md_generator/section_generators/todo_task_tools.py +23 -23
- claude_mpm/services/framework_claude_md_generator.py +3 -2
- claude_mpm/services/health_monitor.py +4 -3
- claude_mpm/services/hook_service.py +64 -4
- claude_mpm/services/infrastructure/__init__.py +21 -0
- claude_mpm/services/infrastructure/logging.py +202 -0
- claude_mpm/services/infrastructure/monitoring.py +893 -0
- claude_mpm/services/memory/indexed_memory.py +648 -0
- claude_mpm/services/project/__init__.py +21 -0
- claude_mpm/services/project/analyzer.py +864 -0
- claude_mpm/services/project/registry.py +608 -0
- claude_mpm/services/project_analyzer.py +95 -2
- claude_mpm/services/recovery_manager.py +15 -9
- claude_mpm/services/socketio/__init__.py +25 -0
- claude_mpm/services/socketio/handlers/__init__.py +25 -0
- claude_mpm/services/socketio/handlers/base.py +121 -0
- claude_mpm/services/socketio/handlers/connection.py +198 -0
- claude_mpm/services/socketio/handlers/file.py +213 -0
- claude_mpm/services/socketio/handlers/git.py +723 -0
- claude_mpm/services/socketio/handlers/memory.py +27 -0
- claude_mpm/services/socketio/handlers/project.py +25 -0
- claude_mpm/services/socketio/handlers/registry.py +145 -0
- claude_mpm/services/socketio_client_manager.py +12 -7
- claude_mpm/services/socketio_server.py +156 -30
- claude_mpm/services/ticket_manager.py +377 -51
- claude_mpm/utils/agent_dependency_loader.py +66 -15
- claude_mpm/utils/error_handler.py +1 -1
- claude_mpm/utils/robust_installer.py +587 -0
- claude_mpm/validation/agent_validator.py +27 -14
- claude_mpm/validation/frontmatter_validator.py +231 -0
- {claude_mpm-3.7.4.dist-info → claude_mpm-3.8.1.dist-info}/METADATA +74 -41
- {claude_mpm-3.7.4.dist-info → claude_mpm-3.8.1.dist-info}/RECORD +101 -76
- claude_mpm/.claude-mpm/logs/hooks_20250728.log +0 -10
- claude_mpm/agents/agent-template.yaml +0 -83
- claude_mpm/cli/README.md +0 -108
- claude_mpm/cli_module/refactoring_guide.md +0 -253
- claude_mpm/config/async_logging_config.yaml +0 -145
- claude_mpm/core/.claude-mpm/logs/hooks_20250730.log +0 -34
- claude_mpm/dashboard/.claude-mpm/memories/README.md +0 -36
- claude_mpm/dashboard/README.md +0 -121
- claude_mpm/dashboard/static/js/dashboard.js.backup +0 -1973
- claude_mpm/dashboard/templates/.claude-mpm/memories/README.md +0 -36
- claude_mpm/dashboard/templates/.claude-mpm/memories/engineer_agent.md +0 -39
- claude_mpm/dashboard/templates/.claude-mpm/memories/version_control_agent.md +0 -38
- claude_mpm/hooks/README.md +0 -96
- claude_mpm/schemas/agent_schema.json +0 -435
- claude_mpm/services/framework_claude_md_generator/README.md +0 -92
- claude_mpm/services/version_control/VERSION +0 -1
- {claude_mpm-3.7.4.dist-info → claude_mpm-3.8.1.dist-info}/WHEEL +0 -0
- {claude_mpm-3.7.4.dist-info → claude_mpm-3.8.1.dist-info}/entry_points.txt +0 -0
- {claude_mpm-3.7.4.dist-info → claude_mpm-3.8.1.dist-info}/licenses/LICENSE +0 -0
- {claude_mpm-3.7.4.dist-info → claude_mpm-3.8.1.dist-info}/top_level.txt +0 -0
| @@ -0,0 +1,432 @@ | |
| 1 | 
            +
            """Interactive session handler for Claude runner.
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            This module provides the InteractiveSession class that manages Claude's interactive mode
         | 
| 4 | 
            +
            with proper separation of concerns and reduced complexity.
         | 
| 5 | 
            +
            """
         | 
| 6 | 
            +
             | 
| 7 | 
            +
            import os
         | 
| 8 | 
            +
            import subprocess
         | 
| 9 | 
            +
            import sys
         | 
| 10 | 
            +
            from pathlib import Path
         | 
| 11 | 
            +
            from typing import Optional, Dict, Any, Tuple
         | 
| 12 | 
            +
            import uuid
         | 
| 13 | 
            +
            from datetime import datetime
         | 
| 14 | 
            +
            import json
         | 
| 15 | 
            +
             | 
| 16 | 
            +
            from claude_mpm.core.logger import get_logger
         | 
| 17 | 
            +
             | 
| 18 | 
            +
             | 
| 19 | 
            +
            class InteractiveSession:
         | 
| 20 | 
            +
                """
         | 
| 21 | 
            +
                Handles interactive Claude sessions with proper separation of concerns.
         | 
| 22 | 
            +
                
         | 
| 23 | 
            +
                WHY: The original run_interactive() method had complexity of 39 and 262 lines.
         | 
| 24 | 
            +
                This class breaks down that functionality into smaller, focused methods with
         | 
| 25 | 
            +
                complexity <10 and lines <80 each, improving maintainability and testability.
         | 
| 26 | 
            +
                
         | 
| 27 | 
            +
                DESIGN DECISION: Uses composition over inheritance - takes ClaudeRunner as
         | 
| 28 | 
            +
                dependency rather than inheriting from it. This maintains loose coupling
         | 
| 29 | 
            +
                and makes testing easier while preserving all original functionality.
         | 
| 30 | 
            +
                """
         | 
| 31 | 
            +
                
         | 
| 32 | 
            +
                def __init__(self, runner):
         | 
| 33 | 
            +
                    """Initialize interactive session handler.
         | 
| 34 | 
            +
                    
         | 
| 35 | 
            +
                    Args:
         | 
| 36 | 
            +
                        runner: ClaudeRunner instance with all necessary services
         | 
| 37 | 
            +
                    """
         | 
| 38 | 
            +
                    self.runner = runner
         | 
| 39 | 
            +
                    self.logger = get_logger("interactive_session")
         | 
| 40 | 
            +
                    self.session_id = None
         | 
| 41 | 
            +
                    self.original_cwd = os.getcwd()
         | 
| 42 | 
            +
                    
         | 
| 43 | 
            +
                def initialize_interactive_session(self) -> Tuple[bool, Optional[str]]:
         | 
| 44 | 
            +
                    """Initialize the interactive session environment.
         | 
| 45 | 
            +
                    
         | 
| 46 | 
            +
                    Sets up WebSocket connections, generates session IDs, and prepares
         | 
| 47 | 
            +
                    the session for launch.
         | 
| 48 | 
            +
                    
         | 
| 49 | 
            +
                    Returns:
         | 
| 50 | 
            +
                        Tuple of (success, error_message)
         | 
| 51 | 
            +
                    """
         | 
| 52 | 
            +
                    try:
         | 
| 53 | 
            +
                        # Generate session ID
         | 
| 54 | 
            +
                        self.session_id = str(uuid.uuid4())
         | 
| 55 | 
            +
                        
         | 
| 56 | 
            +
                        # Initialize WebSocket if enabled
         | 
| 57 | 
            +
                        if self.runner.enable_websocket:
         | 
| 58 | 
            +
                            success, error = self._initialize_websocket()
         | 
| 59 | 
            +
                            if not success:
         | 
| 60 | 
            +
                                self.logger.warning(f"WebSocket initialization failed: {error}")
         | 
| 61 | 
            +
                                # Continue without WebSocket - not a fatal error
         | 
| 62 | 
            +
                        
         | 
| 63 | 
            +
                        # Display welcome message
         | 
| 64 | 
            +
                        self._display_welcome_message()
         | 
| 65 | 
            +
                        
         | 
| 66 | 
            +
                        # Log session start
         | 
| 67 | 
            +
                        if self.runner.project_logger:
         | 
| 68 | 
            +
                            self.runner.project_logger.log_system(
         | 
| 69 | 
            +
                                "Starting interactive session",
         | 
| 70 | 
            +
                                level="INFO",
         | 
| 71 | 
            +
                                component="session"
         | 
| 72 | 
            +
                            )
         | 
| 73 | 
            +
                        
         | 
| 74 | 
            +
                        return True, None
         | 
| 75 | 
            +
                        
         | 
| 76 | 
            +
                    except Exception as e:
         | 
| 77 | 
            +
                        error_msg = f"Failed to initialize session: {e}"
         | 
| 78 | 
            +
                        self.logger.error(error_msg)
         | 
| 79 | 
            +
                        return False, error_msg
         | 
| 80 | 
            +
                
         | 
| 81 | 
            +
                def setup_interactive_environment(self) -> Tuple[bool, Dict[str, Any]]:
         | 
| 82 | 
            +
                    """Set up the interactive environment including agents and commands.
         | 
| 83 | 
            +
                    
         | 
| 84 | 
            +
                    Deploys system and project agents, prepares the command line,
         | 
| 85 | 
            +
                    and sets up the execution environment.
         | 
| 86 | 
            +
                    
         | 
| 87 | 
            +
                    Returns:
         | 
| 88 | 
            +
                        Tuple of (success, environment_dict)
         | 
| 89 | 
            +
                    """
         | 
| 90 | 
            +
                    try:
         | 
| 91 | 
            +
                        # Deploy system agents
         | 
| 92 | 
            +
                        if not self.runner.setup_agents():
         | 
| 93 | 
            +
                            print("Continuing without native agents...")
         | 
| 94 | 
            +
                        
         | 
| 95 | 
            +
                        # Deploy project-specific agents
         | 
| 96 | 
            +
                        self.runner.deploy_project_agents_to_claude()
         | 
| 97 | 
            +
                        
         | 
| 98 | 
            +
                        # Build command
         | 
| 99 | 
            +
                        cmd = self._build_claude_command()
         | 
| 100 | 
            +
                        
         | 
| 101 | 
            +
                        # Prepare environment
         | 
| 102 | 
            +
                        env = self._prepare_environment()
         | 
| 103 | 
            +
                        
         | 
| 104 | 
            +
                        # Change to user directory if needed
         | 
| 105 | 
            +
                        self._change_to_user_directory(env)
         | 
| 106 | 
            +
                        
         | 
| 107 | 
            +
                        return True, {
         | 
| 108 | 
            +
                            'command': cmd,
         | 
| 109 | 
            +
                            'environment': env,
         | 
| 110 | 
            +
                            'session_id': self.session_id
         | 
| 111 | 
            +
                        }
         | 
| 112 | 
            +
                        
         | 
| 113 | 
            +
                    except Exception as e:
         | 
| 114 | 
            +
                        error_msg = f"Failed to setup environment: {e}"
         | 
| 115 | 
            +
                        self.logger.error(error_msg)
         | 
| 116 | 
            +
                        return False, {}
         | 
| 117 | 
            +
                
         | 
| 118 | 
            +
                def handle_interactive_input(self, environment: Dict[str, Any]) -> bool:
         | 
| 119 | 
            +
                    """Handle the interactive input/output loop.
         | 
| 120 | 
            +
                    
         | 
| 121 | 
            +
                    Launches Claude and manages the interactive session using either
         | 
| 122 | 
            +
                    exec or subprocess method based on configuration.
         | 
| 123 | 
            +
                    
         | 
| 124 | 
            +
                    Args:
         | 
| 125 | 
            +
                        environment: Dictionary with command, env vars, and session info
         | 
| 126 | 
            +
                        
         | 
| 127 | 
            +
                    Returns:
         | 
| 128 | 
            +
                        bool: True if successful, False otherwise
         | 
| 129 | 
            +
                    """
         | 
| 130 | 
            +
                    try:
         | 
| 131 | 
            +
                        cmd = environment['command']
         | 
| 132 | 
            +
                        env = environment['environment']
         | 
| 133 | 
            +
                        
         | 
| 134 | 
            +
                        print("Launching Claude...")
         | 
| 135 | 
            +
                        
         | 
| 136 | 
            +
                        # Log launch attempt
         | 
| 137 | 
            +
                        self._log_launch_attempt(cmd)
         | 
| 138 | 
            +
                        
         | 
| 139 | 
            +
                        # Notify WebSocket if connected
         | 
| 140 | 
            +
                        if self.runner.websocket_server:
         | 
| 141 | 
            +
                            self.runner.websocket_server.claude_status_changed(
         | 
| 142 | 
            +
                                status="starting",
         | 
| 143 | 
            +
                                message="Launching Claude interactive session"
         | 
| 144 | 
            +
                            )
         | 
| 145 | 
            +
                        
         | 
| 146 | 
            +
                        # Launch using selected method
         | 
| 147 | 
            +
                        if self.runner.launch_method == "subprocess":
         | 
| 148 | 
            +
                            return self._launch_subprocess_mode(cmd, env)
         | 
| 149 | 
            +
                        else:
         | 
| 150 | 
            +
                            return self._launch_exec_mode(cmd, env)
         | 
| 151 | 
            +
                            
         | 
| 152 | 
            +
                    except FileNotFoundError as e:
         | 
| 153 | 
            +
                        self._handle_launch_error("FileNotFoundError", e)
         | 
| 154 | 
            +
                        return False
         | 
| 155 | 
            +
                    except PermissionError as e:
         | 
| 156 | 
            +
                        self._handle_launch_error("PermissionError", e)
         | 
| 157 | 
            +
                        return False
         | 
| 158 | 
            +
                    except OSError as e:
         | 
| 159 | 
            +
                        self._handle_launch_error("OSError", e)
         | 
| 160 | 
            +
                        return self._attempt_fallback_launch(environment)
         | 
| 161 | 
            +
                    except KeyboardInterrupt:
         | 
| 162 | 
            +
                        self._handle_keyboard_interrupt()
         | 
| 163 | 
            +
                        return True  # Clean exit
         | 
| 164 | 
            +
                    except Exception as e:
         | 
| 165 | 
            +
                        self._handle_launch_error("Exception", e)
         | 
| 166 | 
            +
                        return self._attempt_fallback_launch(environment)
         | 
| 167 | 
            +
                
         | 
| 168 | 
            +
                def process_interactive_command(self, prompt: str) -> Optional[bool]:
         | 
| 169 | 
            +
                    """Process special interactive commands like /agents.
         | 
| 170 | 
            +
                    
         | 
| 171 | 
            +
                    Args:
         | 
| 172 | 
            +
                        prompt: User input command
         | 
| 173 | 
            +
                        
         | 
| 174 | 
            +
                    Returns:
         | 
| 175 | 
            +
                        Optional[bool]: True if handled, False if error, None if not a special command
         | 
| 176 | 
            +
                    """
         | 
| 177 | 
            +
                    # Check for special commands
         | 
| 178 | 
            +
                    if prompt.strip() == "/agents":
         | 
| 179 | 
            +
                        return self._show_available_agents()
         | 
| 180 | 
            +
                    
         | 
| 181 | 
            +
                    # Not a special command
         | 
| 182 | 
            +
                    return None
         | 
| 183 | 
            +
                
         | 
| 184 | 
            +
                def cleanup_interactive_session(self) -> None:
         | 
| 185 | 
            +
                    """Clean up resources after interactive session ends.
         | 
| 186 | 
            +
                    
         | 
| 187 | 
            +
                    Restores original directory, closes connections, and logs session end.
         | 
| 188 | 
            +
                    """
         | 
| 189 | 
            +
                    try:
         | 
| 190 | 
            +
                        # Restore original directory
         | 
| 191 | 
            +
                        if self.original_cwd and os.path.exists(self.original_cwd):
         | 
| 192 | 
            +
                            try:
         | 
| 193 | 
            +
                                os.chdir(self.original_cwd)
         | 
| 194 | 
            +
                            except OSError:
         | 
| 195 | 
            +
                                pass
         | 
| 196 | 
            +
                        
         | 
| 197 | 
            +
                        # Close WebSocket if connected
         | 
| 198 | 
            +
                        if self.runner.websocket_server:
         | 
| 199 | 
            +
                            self.runner.websocket_server.session_ended()
         | 
| 200 | 
            +
                            self.runner.websocket_server = None
         | 
| 201 | 
            +
                        
         | 
| 202 | 
            +
                        # Log session end
         | 
| 203 | 
            +
                        if self.runner.project_logger:
         | 
| 204 | 
            +
                            self.runner.project_logger.log_system(
         | 
| 205 | 
            +
                                "Interactive session ended",
         | 
| 206 | 
            +
                                level="INFO",
         | 
| 207 | 
            +
                                component="session"
         | 
| 208 | 
            +
                            )
         | 
| 209 | 
            +
                        
         | 
| 210 | 
            +
                        # Log session event
         | 
| 211 | 
            +
                        if self.runner.session_log_file:
         | 
| 212 | 
            +
                            self.runner._log_session_event({
         | 
| 213 | 
            +
                                "event": "session_end",
         | 
| 214 | 
            +
                                "session_id": self.session_id
         | 
| 215 | 
            +
                            })
         | 
| 216 | 
            +
                            
         | 
| 217 | 
            +
                    except Exception as e:
         | 
| 218 | 
            +
                        self.logger.debug(f"Error during cleanup: {e}")
         | 
| 219 | 
            +
                
         | 
| 220 | 
            +
                # Private helper methods (each <80 lines, complexity <10)
         | 
| 221 | 
            +
                
         | 
| 222 | 
            +
                def _initialize_websocket(self) -> Tuple[bool, Optional[str]]:
         | 
| 223 | 
            +
                    """Initialize WebSocket connection for monitoring."""
         | 
| 224 | 
            +
                    try:
         | 
| 225 | 
            +
                        from claude_mpm.services.socketio_server import SocketIOClientProxy
         | 
| 226 | 
            +
                        self.runner.websocket_server = SocketIOClientProxy(port=self.runner.websocket_port)
         | 
| 227 | 
            +
                        self.runner.websocket_server.start()
         | 
| 228 | 
            +
                        self.logger.info("Connected to Socket.IO monitoring server")
         | 
| 229 | 
            +
                        
         | 
| 230 | 
            +
                        # Notify session start
         | 
| 231 | 
            +
                        self.runner.websocket_server.session_started(
         | 
| 232 | 
            +
                            session_id=self.session_id,
         | 
| 233 | 
            +
                            launch_method=self.runner.launch_method,
         | 
| 234 | 
            +
                            working_dir=os.getcwd()
         | 
| 235 | 
            +
                        )
         | 
| 236 | 
            +
                        return True, None
         | 
| 237 | 
            +
                        
         | 
| 238 | 
            +
                    except ImportError as e:
         | 
| 239 | 
            +
                        return False, f"Socket.IO module not available: {e}"
         | 
| 240 | 
            +
                    except ConnectionError as e:
         | 
| 241 | 
            +
                        return False, f"Cannot connect to Socket.IO server: {e}"
         | 
| 242 | 
            +
                    except Exception as e:
         | 
| 243 | 
            +
                        return False, f"Unexpected error with Socket.IO: {e}"
         | 
| 244 | 
            +
                
         | 
| 245 | 
            +
                def _display_welcome_message(self) -> None:
         | 
| 246 | 
            +
                    """Display the interactive session welcome message."""
         | 
| 247 | 
            +
                    version_str = self.runner._get_version()
         | 
| 248 | 
            +
                    
         | 
| 249 | 
            +
                    print("\033[32m╭───────────────────────────────────────────────────╮\033[0m")
         | 
| 250 | 
            +
                    print("\033[32m│\033[0m ✻ Claude MPM - Interactive Session                \033[32m│\033[0m")
         | 
| 251 | 
            +
                    print(f"\033[32m│\033[0m   Version {version_str:<40}\033[32m│\033[0m")
         | 
| 252 | 
            +
                    print("\033[32m│                                                   │\033[0m")
         | 
| 253 | 
            +
                    print("\033[32m│\033[0m   Type '/agents' to see available agents          \033[32m│\033[0m")
         | 
| 254 | 
            +
                    print("\033[32m╰───────────────────────────────────────────────────╯\033[0m")
         | 
| 255 | 
            +
                    print("")  # Add blank line after box
         | 
| 256 | 
            +
                
         | 
| 257 | 
            +
                def _build_claude_command(self) -> list:
         | 
| 258 | 
            +
                    """Build the Claude command with all necessary arguments."""
         | 
| 259 | 
            +
                    cmd = [
         | 
| 260 | 
            +
                        "claude",
         | 
| 261 | 
            +
                        "--model", "opus",
         | 
| 262 | 
            +
                        "--dangerously-skip-permissions"
         | 
| 263 | 
            +
                    ]
         | 
| 264 | 
            +
                    
         | 
| 265 | 
            +
                    # Add custom arguments
         | 
| 266 | 
            +
                    if self.runner.claude_args:
         | 
| 267 | 
            +
                        cmd.extend(self.runner.claude_args)
         | 
| 268 | 
            +
                    
         | 
| 269 | 
            +
                    # Add system instructions
         | 
| 270 | 
            +
                    from claude_mpm.core.claude_runner import create_simple_context
         | 
| 271 | 
            +
                    system_prompt = self.runner._create_system_prompt()
         | 
| 272 | 
            +
                    if system_prompt and system_prompt != create_simple_context():
         | 
| 273 | 
            +
                        cmd.extend(["--append-system-prompt", system_prompt])
         | 
| 274 | 
            +
                    
         | 
| 275 | 
            +
                    return cmd
         | 
| 276 | 
            +
                
         | 
| 277 | 
            +
                def _prepare_environment(self) -> dict:
         | 
| 278 | 
            +
                    """Prepare clean environment variables for Claude."""
         | 
| 279 | 
            +
                    clean_env = os.environ.copy()
         | 
| 280 | 
            +
                    
         | 
| 281 | 
            +
                    # Remove Claude-specific variables that might interfere
         | 
| 282 | 
            +
                    claude_vars_to_remove = [
         | 
| 283 | 
            +
                        'CLAUDE_CODE_ENTRYPOINT', 'CLAUDECODE', 'CLAUDE_CONFIG_DIR',
         | 
| 284 | 
            +
                        'CLAUDE_MAX_PARALLEL_SUBAGENTS', 'CLAUDE_TIMEOUT'
         | 
| 285 | 
            +
                    ]
         | 
| 286 | 
            +
                    for var in claude_vars_to_remove:
         | 
| 287 | 
            +
                        clean_env.pop(var, None)
         | 
| 288 | 
            +
                    
         | 
| 289 | 
            +
                    return clean_env
         | 
| 290 | 
            +
                
         | 
| 291 | 
            +
                def _change_to_user_directory(self, env: dict) -> None:
         | 
| 292 | 
            +
                    """Change to user's working directory if specified."""
         | 
| 293 | 
            +
                    if 'CLAUDE_MPM_USER_PWD' in env:
         | 
| 294 | 
            +
                        user_pwd = env['CLAUDE_MPM_USER_PWD']
         | 
| 295 | 
            +
                        env['CLAUDE_WORKSPACE'] = user_pwd
         | 
| 296 | 
            +
                        
         | 
| 297 | 
            +
                        try:
         | 
| 298 | 
            +
                            os.chdir(user_pwd)
         | 
| 299 | 
            +
                            self.logger.info(f"Changed working directory to: {user_pwd}")
         | 
| 300 | 
            +
                        except (PermissionError, FileNotFoundError, OSError) as e:
         | 
| 301 | 
            +
                            self.logger.warning(f"Could not change to directory {user_pwd}: {e}")
         | 
| 302 | 
            +
                
         | 
| 303 | 
            +
                def _log_launch_attempt(self, cmd: list) -> None:
         | 
| 304 | 
            +
                    """Log the Claude launch attempt."""
         | 
| 305 | 
            +
                    if self.runner.project_logger:
         | 
| 306 | 
            +
                        self.runner.project_logger.log_system(
         | 
| 307 | 
            +
                            f"Launching Claude interactive mode with {self.runner.launch_method}",
         | 
| 308 | 
            +
                            level="INFO",
         | 
| 309 | 
            +
                            component="session"
         | 
| 310 | 
            +
                        )
         | 
| 311 | 
            +
                        self.runner._log_session_event({
         | 
| 312 | 
            +
                            "event": "launching_claude_interactive",
         | 
| 313 | 
            +
                            "command": " ".join(cmd),
         | 
| 314 | 
            +
                            "method": self.runner.launch_method
         | 
| 315 | 
            +
                        })
         | 
| 316 | 
            +
                
         | 
| 317 | 
            +
                def _launch_exec_mode(self, cmd: list, env: dict) -> bool:
         | 
| 318 | 
            +
                    """Launch Claude using exec mode (replaces current process)."""
         | 
| 319 | 
            +
                    # Notify WebSocket before exec
         | 
| 320 | 
            +
                    if self.runner.websocket_server:
         | 
| 321 | 
            +
                        self.runner.websocket_server.claude_status_changed(
         | 
| 322 | 
            +
                            status="running",
         | 
| 323 | 
            +
                            message="Claude process started (exec mode)"
         | 
| 324 | 
            +
                        )
         | 
| 325 | 
            +
                    
         | 
| 326 | 
            +
                    # This will not return if successful
         | 
| 327 | 
            +
                    os.execvpe(cmd[0], cmd, env)
         | 
| 328 | 
            +
                    return False  # Only reached on failure
         | 
| 329 | 
            +
                
         | 
| 330 | 
            +
                def _launch_subprocess_mode(self, cmd: list, env: dict) -> bool:
         | 
| 331 | 
            +
                    """Launch Claude as subprocess with PTY."""
         | 
| 332 | 
            +
                    # Delegate to runner's existing method
         | 
| 333 | 
            +
                    self.runner._launch_subprocess_interactive(cmd, env)
         | 
| 334 | 
            +
                    return True
         | 
| 335 | 
            +
                
         | 
| 336 | 
            +
                def _handle_launch_error(self, error_type: str, error: Exception) -> None:
         | 
| 337 | 
            +
                    """Handle errors during Claude launch."""
         | 
| 338 | 
            +
                    error_messages = {
         | 
| 339 | 
            +
                        "FileNotFoundError": "Claude CLI not found. Please ensure 'claude' is installed and in your PATH",
         | 
| 340 | 
            +
                        "PermissionError": "Permission denied executing Claude CLI",
         | 
| 341 | 
            +
                        "OSError": "OS error launching Claude",
         | 
| 342 | 
            +
                        "Exception": "Unexpected error launching Claude"
         | 
| 343 | 
            +
                    }
         | 
| 344 | 
            +
                    
         | 
| 345 | 
            +
                    error_msg = f"{error_messages.get(error_type, 'Error')}: {error}"
         | 
| 346 | 
            +
                    print(f"❌ {error_msg}")
         | 
| 347 | 
            +
                    
         | 
| 348 | 
            +
                    if self.runner.project_logger:
         | 
| 349 | 
            +
                        self.runner.project_logger.log_system(error_msg, level="ERROR", component="session")
         | 
| 350 | 
            +
                        self.runner._log_session_event({
         | 
| 351 | 
            +
                            "event": "interactive_launch_failed",
         | 
| 352 | 
            +
                            "error": str(error),
         | 
| 353 | 
            +
                            "exception_type": error_type
         | 
| 354 | 
            +
                        })
         | 
| 355 | 
            +
                    
         | 
| 356 | 
            +
                    # Notify WebSocket of error
         | 
| 357 | 
            +
                    if self.runner.websocket_server:
         | 
| 358 | 
            +
                        self.runner.websocket_server.claude_status_changed(
         | 
| 359 | 
            +
                            status="error",
         | 
| 360 | 
            +
                            message=f"Failed to launch Claude: {error}"
         | 
| 361 | 
            +
                        )
         | 
| 362 | 
            +
                
         | 
| 363 | 
            +
                def _handle_keyboard_interrupt(self) -> None:
         | 
| 364 | 
            +
                    """Handle keyboard interrupt during session."""
         | 
| 365 | 
            +
                    print("\n⚠️  Session interrupted by user")
         | 
| 366 | 
            +
                    
         | 
| 367 | 
            +
                    if self.runner.project_logger:
         | 
| 368 | 
            +
                        self.runner.project_logger.log_system(
         | 
| 369 | 
            +
                            "Session interrupted by user",
         | 
| 370 | 
            +
                            level="INFO",
         | 
| 371 | 
            +
                            component="session"
         | 
| 372 | 
            +
                        )
         | 
| 373 | 
            +
                        self.runner._log_session_event({
         | 
| 374 | 
            +
                            "event": "session_interrupted",
         | 
| 375 | 
            +
                            "reason": "user_interrupt"
         | 
| 376 | 
            +
                        })
         | 
| 377 | 
            +
                
         | 
| 378 | 
            +
                def _attempt_fallback_launch(self, environment: Dict[str, Any]) -> bool:
         | 
| 379 | 
            +
                    """Attempt fallback launch using subprocess."""
         | 
| 380 | 
            +
                    print("\n🔄 Attempting fallback launch method...")
         | 
| 381 | 
            +
                    
         | 
| 382 | 
            +
                    try:
         | 
| 383 | 
            +
                        cmd = environment['command']
         | 
| 384 | 
            +
                        env = environment['environment']
         | 
| 385 | 
            +
                        
         | 
| 386 | 
            +
                        result = subprocess.run(cmd, stdin=None, stdout=None, stderr=None, env=env)
         | 
| 387 | 
            +
                        
         | 
| 388 | 
            +
                        if result.returncode == 0:
         | 
| 389 | 
            +
                            if self.runner.project_logger:
         | 
| 390 | 
            +
                                self.runner.project_logger.log_system(
         | 
| 391 | 
            +
                                    "Interactive session completed (subprocess fallback)",
         | 
| 392 | 
            +
                                    level="INFO",
         | 
| 393 | 
            +
                                    component="session"
         | 
| 394 | 
            +
                                )
         | 
| 395 | 
            +
                            return True
         | 
| 396 | 
            +
                        else:
         | 
| 397 | 
            +
                            print(f"⚠️  Claude exited with code {result.returncode}")
         | 
| 398 | 
            +
                            return False
         | 
| 399 | 
            +
                            
         | 
| 400 | 
            +
                    except FileNotFoundError:
         | 
| 401 | 
            +
                        print("❌ Fallback failed: Claude CLI not found in PATH")
         | 
| 402 | 
            +
                        print("\n💡 To fix this issue:")
         | 
| 403 | 
            +
                        print("   1. Install Claude CLI: npm install -g @anthropic-ai/claude-ai")
         | 
| 404 | 
            +
                        print("   2. Or specify the full path to the claude binary")
         | 
| 405 | 
            +
                        return False
         | 
| 406 | 
            +
                    except KeyboardInterrupt:
         | 
| 407 | 
            +
                        print("\n⚠️  Fallback interrupted by user")
         | 
| 408 | 
            +
                        return True
         | 
| 409 | 
            +
                    except Exception as e:
         | 
| 410 | 
            +
                        print(f"❌ Fallback failed with unexpected error: {e}")
         | 
| 411 | 
            +
                        return False
         | 
| 412 | 
            +
                
         | 
| 413 | 
            +
                def _show_available_agents(self) -> bool:
         | 
| 414 | 
            +
                    """Show available agents in the system."""
         | 
| 415 | 
            +
                    try:
         | 
| 416 | 
            +
                        from claude_mpm.cli import _get_agent_versions_display
         | 
| 417 | 
            +
                        agent_versions = _get_agent_versions_display()
         | 
| 418 | 
            +
                        
         | 
| 419 | 
            +
                        if agent_versions:
         | 
| 420 | 
            +
                            print(agent_versions)
         | 
| 421 | 
            +
                        else:
         | 
| 422 | 
            +
                            print("No deployed agents found")
         | 
| 423 | 
            +
                            print("\nTo deploy agents, run: claude-mpm --mpm:agents deploy")
         | 
| 424 | 
            +
                        
         | 
| 425 | 
            +
                        return True
         | 
| 426 | 
            +
                        
         | 
| 427 | 
            +
                    except ImportError:
         | 
| 428 | 
            +
                        print("Error: CLI module not available")
         | 
| 429 | 
            +
                        return False
         | 
| 430 | 
            +
                    except Exception as e:
         | 
| 431 | 
            +
                        print(f"Error getting agent versions: {e}")
         | 
| 432 | 
            +
                        return False
         |