claude-mpm 3.4.3__py3-none-any.whl → 3.4.6__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.
@@ -1,261 +0,0 @@
1
- #!/usr/bin/env python3
2
- """Socket.IO Dashboard Launcher for Claude MPM.
3
-
4
- WHY: This script provides a streamlined solution for launching the Socket.IO
5
- monitoring dashboard using only the Python Socket.IO server implementation.
6
- It handles server startup, dashboard creation, and browser opening.
7
-
8
- DESIGN DECISION: Uses only python-socketio and aiohttp for a clean,
9
- Node.js-free implementation. This simplifies deployment and reduces
10
- dependencies while maintaining full functionality.
11
-
12
- The script handles:
13
- 1. Python Socket.IO server startup
14
- 2. Dashboard HTML creation and serving
15
- 3. Browser opening with proper URL construction
16
- 4. Background/daemon mode operation
17
- 5. Graceful error handling and user feedback
18
- """
19
-
20
- import argparse
21
- import os
22
- import sys
23
- import time
24
- import webbrowser
25
- import signal
26
- from pathlib import Path
27
- from typing import Optional
28
-
29
- # Get script directory for relative paths
30
- SCRIPT_DIR = Path(__file__).parent
31
- PROJECT_ROOT = SCRIPT_DIR.parent.parent.parent # Go up to project root from src/claude_mpm/scripts/
32
-
33
- def check_python_dependencies() -> bool:
34
- """Check if Python Socket.IO dependencies are available.
35
-
36
- WHY: We need python-socketio and aiohttp packages for the server.
37
- This function validates the environment and provides clear feedback.
38
-
39
- Returns:
40
- bool: True if Python dependencies are ready, False otherwise
41
- """
42
- try:
43
- import socketio
44
- import aiohttp
45
- socketio_version = getattr(socketio, '__version__', 'unknown')
46
- aiohttp_version = getattr(aiohttp, '__version__', 'unknown')
47
- print(f"✓ python-socketio v{socketio_version} detected")
48
- print(f"✓ aiohttp v{aiohttp_version} detected")
49
- return True
50
- except ImportError as e:
51
- print(f"❌ Required Python packages missing: {e}")
52
- print(" Install with: pip install python-socketio aiohttp")
53
- return False
54
-
55
-
56
-
57
- def check_dashboard_availability(port: int):
58
- """Check if the modular dashboard is available.
59
-
60
- WHY: The new architecture uses a modular dashboard served by the Socket.IO server
61
- instead of creating static HTML files. This validates the proper dashboard exists.
62
-
63
- Args:
64
- port: Port number for the Socket.IO server
65
- """
66
- # Check if new modular dashboard is available
67
- web_templates_dir = PROJECT_ROOT / "src" / "claude_mpm" / "web" / "templates"
68
- modular_dashboard = web_templates_dir / "index.html"
69
- if modular_dashboard.exists():
70
- print(f"✓ Modular dashboard found at {modular_dashboard}")
71
- return True
72
- else:
73
- print(f"⚠️ Modular dashboard not found at {modular_dashboard}")
74
- print(f" Expected path: {modular_dashboard}")
75
- return False
76
-
77
- def check_server_running(port: int) -> bool:
78
- """Check if a Socket.IO server is already running on the specified port.
79
-
80
- WHY: We want to avoid starting multiple servers on the same port
81
- and provide clear feedback to users about existing servers.
82
-
83
- Args:
84
- port: Port number to check
85
-
86
- Returns:
87
- bool: True if server is running, False otherwise
88
- """
89
- try:
90
- import socket
91
- with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
92
- s.settimeout(1)
93
- result = s.connect_ex(('127.0.0.1', port))
94
- if result == 0:
95
- print(f"✓ Socket.IO server already running on port {port}")
96
- return True
97
- except Exception:
98
- pass
99
-
100
- return False
101
-
102
- def start_python_server(port: int, daemon: bool = False) -> Optional:
103
- """Start the Python Socket.IO server.
104
-
105
- WHY: Uses python-socketio and aiohttp for a clean, Node.js-free
106
- implementation that handles all Socket.IO functionality.
107
-
108
- Args:
109
- port: Port number for the server
110
- daemon: Whether to run in background mode
111
-
112
- Returns:
113
- Thread object if successful, None otherwise
114
- """
115
- try:
116
- # Import the existing Python Socket.IO server
117
- sys.path.insert(0, str(PROJECT_ROOT / "src"))
118
- from claude_mpm.services.socketio_server import SocketIOServer
119
-
120
- server = SocketIOServer(port=port)
121
-
122
- if daemon:
123
- # Start in background thread
124
- server.start()
125
- print(f"🚀 Python Socket.IO server started on port {port}")
126
- return server.thread
127
- else:
128
- # Start and block
129
- print(f"🚀 Starting Python Socket.IO server on port {port}")
130
- server.start()
131
-
132
- # Keep alive until interrupted
133
- try:
134
- while server.running:
135
- time.sleep(1)
136
- except KeyboardInterrupt:
137
- print("\\n🛑 Shutting down Python server...")
138
- server.stop()
139
-
140
- return None
141
-
142
- except Exception as e:
143
- print(f"❌ Failed to start Python server: {e}")
144
- return None
145
-
146
- def open_dashboard(port: int, no_browser: bool = False):
147
- """Open the Socket.IO dashboard in browser.
148
-
149
- WHY: Users need easy access to the monitoring dashboard. This function
150
- handles URL construction and browser opening with fallback options.
151
- Now uses the new modular dashboard location.
152
-
153
- Args:
154
- port: Port number for the Socket.IO server
155
- no_browser: Skip browser opening if True
156
- """
157
- if no_browser:
158
- print(f"📊 Dashboard available at: http://localhost:{port}/dashboard")
159
- return
160
-
161
- dashboard_url = f"http://localhost:{port}/dashboard?autoconnect=true&port={port}"
162
-
163
- try:
164
- print(f"🌐 Opening dashboard: {dashboard_url}")
165
- webbrowser.open(dashboard_url)
166
-
167
- except Exception as e:
168
- print(f"⚠️ Failed to open browser automatically: {e}")
169
- print(f"📊 Dashboard: {dashboard_url}")
170
-
171
- def cleanup_handler(signum, frame):
172
- """Handle cleanup on shutdown signals.
173
-
174
- WHY: Proper cleanup ensures sockets are closed and resources freed
175
- when the script is terminated.
176
- """
177
- print("\\n🛑 Shutting down Socket.IO launcher...")
178
- sys.exit(0)
179
-
180
- def main():
181
- """Main entry point for the Socket.IO dashboard launcher.
182
-
183
- WHY: This orchestrates the entire launch process, from dependency checking
184
- to server startup and dashboard opening, with comprehensive error handling.
185
- """
186
- parser = argparse.ArgumentParser(
187
- description="Launch Socket.IO dashboard for Claude MPM monitoring",
188
- formatter_class=argparse.RawDescriptionHelpFormatter,
189
- epilog='''
190
- Examples:
191
- python launch_socketio_dashboard.py # Start with default settings
192
- python launch_socketio_dashboard.py --port 3000 # Use specific port
193
- python launch_socketio_dashboard.py --daemon # Run in background
194
- python launch_socketio_dashboard.py --no-browser # Don't open browser
195
- python launch_socketio_dashboard.py --setup-only # Just create files
196
- '''
197
- )
198
-
199
- parser.add_argument('--port', type=int, default=3000,
200
- help='Socket.IO server port (default: 3000)')
201
- parser.add_argument('--daemon', action='store_true',
202
- help='Run server in background mode')
203
- parser.add_argument('--no-browser', action='store_true',
204
- help='Skip opening browser automatically')
205
- parser.add_argument('--setup-only', action='store_true',
206
- help='Create necessary files without starting server')
207
-
208
- args = parser.parse_args()
209
-
210
- # Setup signal handlers
211
- signal.signal(signal.SIGINT, cleanup_handler)
212
- signal.signal(signal.SIGTERM, cleanup_handler)
213
-
214
- print("🚀 Claude MPM Socket.IO Dashboard Launcher")
215
- print("=" * 50)
216
-
217
- # Check dashboard availability (modular dashboard)
218
- check_dashboard_availability(args.port)
219
-
220
- if args.setup_only:
221
- # Just setup files, don't start server
222
- print("📁 Setup complete - files created")
223
- return
224
-
225
- # Check if server is already running
226
- if check_server_running(args.port):
227
- print(f"✅ Using existing server on port {args.port}")
228
- open_dashboard(args.port, args.no_browser)
229
- return
230
-
231
- # Check Python dependencies
232
- if not check_python_dependencies():
233
- print("❌ Required Python packages not available")
234
- sys.exit(1)
235
-
236
- # Start Python Socket.IO server
237
- print("🟢 Using Python Socket.IO server")
238
-
239
- try:
240
- server_thread = start_python_server(args.port, args.daemon)
241
-
242
- if server_thread or not args.daemon:
243
- # Server started or is starting
244
- time.sleep(2) # Give server time to start
245
- open_dashboard(args.port, args.no_browser)
246
-
247
- if args.daemon and server_thread:
248
- print(f"🔄 Python server running in background")
249
- print(f" Dashboard: http://localhost:{args.port}/dashboard")
250
- else:
251
- print("❌ Failed to start Socket.IO server")
252
- sys.exit(1)
253
-
254
- except KeyboardInterrupt:
255
- print("\\n✅ Socket.IO launcher stopped")
256
- except Exception as e:
257
- print(f"❌ Launcher error: {e}")
258
- sys.exit(1)
259
-
260
- if __name__ == "__main__":
261
- main()