claude-mpm 4.5.6__py3-none-any.whl → 4.5.11__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.
Files changed (62) hide show
  1. claude_mpm/VERSION +1 -1
  2. claude_mpm/__init__.py +20 -5
  3. claude_mpm/agents/BASE_OPS.md +10 -0
  4. claude_mpm/agents/PM_INSTRUCTIONS.md +28 -4
  5. claude_mpm/agents/agent_loader.py +19 -2
  6. claude_mpm/agents/base_agent_loader.py +5 -5
  7. claude_mpm/agents/templates/agent-manager.json +3 -3
  8. claude_mpm/agents/templates/agentic-coder-optimizer.json +3 -3
  9. claude_mpm/agents/templates/api_qa.json +1 -1
  10. claude_mpm/agents/templates/clerk-ops.json +3 -3
  11. claude_mpm/agents/templates/code_analyzer.json +3 -3
  12. claude_mpm/agents/templates/dart_engineer.json +294 -0
  13. claude_mpm/agents/templates/data_engineer.json +3 -3
  14. claude_mpm/agents/templates/documentation.json +2 -2
  15. claude_mpm/agents/templates/engineer.json +2 -2
  16. claude_mpm/agents/templates/gcp_ops_agent.json +2 -2
  17. claude_mpm/agents/templates/imagemagick.json +1 -1
  18. claude_mpm/agents/templates/local_ops_agent.json +363 -49
  19. claude_mpm/agents/templates/memory_manager.json +2 -2
  20. claude_mpm/agents/templates/nextjs_engineer.json +2 -2
  21. claude_mpm/agents/templates/ops.json +2 -2
  22. claude_mpm/agents/templates/php-engineer.json +1 -1
  23. claude_mpm/agents/templates/project_organizer.json +1 -1
  24. claude_mpm/agents/templates/prompt-engineer.json +6 -4
  25. claude_mpm/agents/templates/python_engineer.json +2 -2
  26. claude_mpm/agents/templates/qa.json +1 -1
  27. claude_mpm/agents/templates/react_engineer.json +3 -3
  28. claude_mpm/agents/templates/refactoring_engineer.json +3 -3
  29. claude_mpm/agents/templates/research.json +2 -2
  30. claude_mpm/agents/templates/security.json +2 -2
  31. claude_mpm/agents/templates/ticketing.json +2 -2
  32. claude_mpm/agents/templates/typescript_engineer.json +2 -2
  33. claude_mpm/agents/templates/vercel_ops_agent.json +2 -2
  34. claude_mpm/agents/templates/version_control.json +2 -2
  35. claude_mpm/agents/templates/web_qa.json +6 -6
  36. claude_mpm/agents/templates/web_ui.json +3 -3
  37. claude_mpm/cli/__init__.py +49 -19
  38. claude_mpm/cli/commands/configure.py +591 -7
  39. claude_mpm/cli/parsers/configure_parser.py +5 -0
  40. claude_mpm/core/__init__.py +53 -17
  41. claude_mpm/core/config.py +1 -1
  42. claude_mpm/core/log_manager.py +7 -0
  43. claude_mpm/hooks/claude_hooks/response_tracking.py +16 -11
  44. claude_mpm/hooks/claude_hooks/services/connection_manager_http.py +9 -11
  45. claude_mpm/services/__init__.py +140 -156
  46. claude_mpm/services/agents/deployment/deployment_config_loader.py +21 -0
  47. claude_mpm/services/agents/loading/base_agent_manager.py +12 -2
  48. claude_mpm/services/async_session_logger.py +112 -96
  49. claude_mpm/services/claude_session_logger.py +63 -61
  50. claude_mpm/services/mcp_config_manager.py +328 -38
  51. claude_mpm/services/mcp_gateway/__init__.py +98 -94
  52. claude_mpm/services/monitor/event_emitter.py +1 -1
  53. claude_mpm/services/orphan_detection.py +791 -0
  54. claude_mpm/services/project_port_allocator.py +601 -0
  55. claude_mpm/services/response_tracker.py +17 -6
  56. claude_mpm/services/session_manager.py +176 -0
  57. {claude_mpm-4.5.6.dist-info → claude_mpm-4.5.11.dist-info}/METADATA +1 -1
  58. {claude_mpm-4.5.6.dist-info → claude_mpm-4.5.11.dist-info}/RECORD +62 -58
  59. {claude_mpm-4.5.6.dist-info → claude_mpm-4.5.11.dist-info}/WHEEL +0 -0
  60. {claude_mpm-4.5.6.dist-info → claude_mpm-4.5.11.dist-info}/entry_points.txt +0 -0
  61. {claude_mpm-4.5.6.dist-info → claude_mpm-4.5.11.dist-info}/licenses/LICENSE +0 -0
  62. {claude_mpm-4.5.6.dist-info → claude_mpm-4.5.11.dist-info}/top_level.txt +0 -0
@@ -31,6 +31,9 @@ from typing import Any, Dict, Optional
31
31
  from claude_mpm.core.constants import PerformanceConfig, SystemLimits, TimeoutConfig
32
32
  from claude_mpm.core.logging_utils import get_logger
33
33
 
34
+ # Import centralized session manager
35
+ from claude_mpm.services.session_manager import get_session_manager
36
+
34
37
  # Import configuration manager
35
38
  from ..core.config import Config
36
39
 
@@ -68,8 +71,13 @@ class AsyncSessionLogger:
68
71
  - Configurable log formats (JSON, syslog, journald)
69
72
  - Fire-and-forget pattern for zero latency impact
70
73
  - Graceful degradation on errors
74
+ - Thread-safe singleton pattern with initialization flag
71
75
  """
72
76
 
77
+ _initialization_lock = Lock()
78
+ _initialized = False
79
+ _worker_started = False
80
+
73
81
  def __init__(
74
82
  self,
75
83
  base_dir: Optional[Path] = None,
@@ -90,109 +98,108 @@ class AsyncSessionLogger:
90
98
  enable_compression: Enable gzip compression for JSON logs (overrides config)
91
99
  config: Configuration instance to use (creates new if not provided)
92
100
  """
93
- # Load configuration from YAML file or use provided config
94
- if config is None:
95
- config = Config()
96
- self.config = config
97
-
98
- # Get response logging configuration section
99
- response_config = self.config.get("response_logging", {})
100
-
101
- # Apply configuration with parameter overrides
102
- self.base_dir = Path(
103
- base_dir
104
- or response_config.get("session_directory", ".claude-mpm/responses")
105
- )
106
-
107
- # Convert log format string to enum
108
- format_str = response_config.get("format", "json").lower()
109
- if log_format is not None:
110
- self.log_format = log_format
111
- elif format_str == "syslog":
112
- self.log_format = LogFormat.SYSLOG
113
- elif format_str == "journald":
114
- self.log_format = LogFormat.JOURNALD
115
- else:
116
- self.log_format = LogFormat.JSON
117
-
118
- self.max_queue_size = (
119
- max_queue_size
120
- if max_queue_size is not None
121
- else response_config.get("max_queue_size", SystemLimits.MAX_QUEUE_SIZE)
122
- )
123
-
124
- # Handle async configuration with backward compatibility
125
- if enable_async is not None:
126
- self.enable_async = enable_async
127
- else:
128
- # Check configuration first, then environment variables for backward compatibility
129
- self.enable_async = response_config.get("use_async", True)
130
- # Override with environment variable if set (backward compatibility)
131
- if os.environ.get("CLAUDE_USE_ASYNC_LOG"):
132
- self.enable_async = (
133
- os.environ.get("CLAUDE_USE_ASYNC_LOG", "true").lower() == "true"
134
- )
135
-
136
- # Check debug sync mode (forces synchronous for debugging)
137
- if (
138
- response_config.get("debug_sync", False)
139
- or os.environ.get("CLAUDE_LOG_SYNC", "").lower() == "true"
140
- ):
141
- logger.info("Debug sync mode enabled - forcing synchronous logging")
142
- self.enable_async = False
143
-
144
- self.enable_compression = (
145
- enable_compression
146
- if enable_compression is not None
147
- else response_config.get("enable_compression", False)
148
- )
101
+ # Use initialization flag to prevent duplicate setup
102
+ with self._initialization_lock:
103
+ if self._initialized and hasattr(self, "config"):
104
+ logger.debug("AsyncSessionLogger already initialized, skipping setup")
105
+ return
149
106
 
150
- # Create base directory
151
- self.base_dir.mkdir(parents=True, exist_ok=True)
107
+ # Load configuration from YAML file or use provided config
108
+ if config is None:
109
+ config = Config()
110
+ self.config = config
152
111
 
153
- # Session management
154
- self.session_id = self._get_claude_session_id()
112
+ # Get response logging configuration section
113
+ response_config = self.config.get("response_logging", {})
155
114
 
156
- # Async infrastructure
157
- self._queue: Queue = Queue(maxsize=self.max_queue_size)
158
- self._worker_thread: Optional[Thread] = None
159
- self._shutdown = False
160
- self._lock = Lock()
115
+ # Apply configuration with parameter overrides
116
+ self.base_dir = Path(
117
+ base_dir
118
+ or response_config.get("session_directory", ".claude-mpm/responses")
119
+ )
161
120
 
162
- # Statistics
163
- self.stats = {
164
- "logged": 0,
165
- "queued": 0,
166
- "dropped": 0,
167
- "errors": 0,
168
- "avg_write_time_ms": 0.0,
169
- }
121
+ # Convert log format string to enum
122
+ format_str = response_config.get("format", "json").lower()
123
+ if log_format is not None:
124
+ self.log_format = log_format
125
+ elif format_str == "syslog":
126
+ self.log_format = LogFormat.SYSLOG
127
+ elif format_str == "journald":
128
+ self.log_format = LogFormat.JOURNALD
129
+ else:
130
+ self.log_format = LogFormat.JSON
170
131
 
171
- # Initialize format-specific handlers
172
- self._init_format_handler()
132
+ self.max_queue_size = (
133
+ max_queue_size
134
+ if max_queue_size is not None
135
+ else response_config.get("max_queue_size", SystemLimits.MAX_QUEUE_SIZE)
136
+ )
173
137
 
174
- # Start background worker if async enabled
175
- if self.enable_async:
176
- self._start_worker()
138
+ # Handle async configuration with backward compatibility
139
+ if enable_async is not None:
140
+ self.enable_async = enable_async
141
+ else:
142
+ # Check configuration first, then environment variables for backward compatibility
143
+ self.enable_async = response_config.get("use_async", True)
144
+ # Override with environment variable if set (backward compatibility)
145
+ if os.environ.get("CLAUDE_USE_ASYNC_LOG"):
146
+ self.enable_async = (
147
+ os.environ.get("CLAUDE_USE_ASYNC_LOG", "true").lower() == "true"
148
+ )
177
149
 
178
- # Log initialization status
179
- logger.info(
180
- f"AsyncSessionLogger initialized: session_id={self.session_id}, async={self.enable_async}, format={self.log_format.value}"
181
- )
150
+ # Check debug sync mode (forces synchronous for debugging)
151
+ if (
152
+ response_config.get("debug_sync", False)
153
+ or os.environ.get("CLAUDE_LOG_SYNC", "").lower() == "true"
154
+ ):
155
+ logger.info("Debug sync mode enabled - forcing synchronous logging")
156
+ self.enable_async = False
157
+
158
+ self.enable_compression = (
159
+ enable_compression
160
+ if enable_compression is not None
161
+ else response_config.get("enable_compression", False)
162
+ )
182
163
 
183
- def _get_claude_session_id(self) -> str:
184
- """Get or generate a Claude session ID."""
185
- # Check environment variables in order of preference
186
- for env_var in ["CLAUDE_SESSION_ID", "ANTHROPIC_SESSION_ID", "SESSION_ID"]:
187
- session_id = os.environ.get(env_var)
188
- if session_id:
189
- logger.info(f"Using session ID from {env_var}: {session_id}")
190
- return session_id
164
+ # Create base directory
165
+ self.base_dir.mkdir(parents=True, exist_ok=True)
166
+
167
+ # Use centralized SessionManager for session ID
168
+ session_manager = get_session_manager()
169
+ self.session_id = session_manager.get_session_id()
170
+
171
+ # Async infrastructure
172
+ self._queue: Queue = Queue(maxsize=self.max_queue_size)
173
+ self._worker_thread: Optional[Thread] = None
174
+ self._shutdown = False
175
+ self._lock = Lock()
176
+
177
+ # Statistics
178
+ self.stats = {
179
+ "logged": 0,
180
+ "queued": 0,
181
+ "dropped": 0,
182
+ "errors": 0,
183
+ "avg_write_time_ms": 0.0,
184
+ }
185
+
186
+ # Initialize format-specific handlers
187
+ self._init_format_handler()
188
+
189
+ # Mark as initialized
190
+ self._initialized = True
191
+
192
+ # Log initialization status
193
+ logger.debug(
194
+ f"AsyncSessionLogger initialized with SessionManager: session_id={self.session_id}, async={self.enable_async}, format={self.log_format.value}"
195
+ )
191
196
 
192
- # Generate timestamp-based session ID
193
- session_id = datetime.now(timezone.utc).strftime("%Y%m%d_%H%M%S")
194
- logger.info(f"Generated session ID: {session_id}")
195
- return session_id
197
+ # Start background worker if async enabled (outside initialization lock)
198
+ if self.enable_async and not self._worker_started:
199
+ with self._initialization_lock:
200
+ if not self._worker_started:
201
+ self._start_worker()
202
+ self._worker_started = True
196
203
 
197
204
  def _init_format_handler(self):
198
205
  """Initialize format-specific logging handlers."""
@@ -519,9 +526,18 @@ class AsyncSessionLogger:
519
526
  return self.stats.copy()
520
527
 
521
528
  def set_session_id(self, session_id: str):
522
- """Set a new session ID."""
529
+ """Set a new session ID.
530
+
531
+ Note: This updates both the local session ID and the SessionManager.
532
+
533
+ Args:
534
+ session_id: The new session ID to use
535
+ """
523
536
  self.session_id = session_id
524
- logger.info(f"Session ID updated to: {session_id}")
537
+ # Also update SessionManager to keep consistency
538
+ session_manager = get_session_manager()
539
+ session_manager.set_session_id(session_id)
540
+ logger.debug(f"Session ID updated to: {session_id}")
525
541
 
526
542
  def is_enabled(self) -> bool:
527
543
  """Check if logging is enabled."""
@@ -13,11 +13,15 @@ Configuration via .claude-mpm/configuration.yaml.
13
13
  import json
14
14
  import os
15
15
  from datetime import datetime, timezone
16
+ from threading import Lock
16
17
  from typing import Any, Dict, Optional
17
18
 
18
19
  # Import configuration manager
19
20
  from claude_mpm.core.config import Config
20
21
 
22
+ # Import centralized session manager
23
+ from claude_mpm.services.session_manager import get_session_manager
24
+
21
25
  # Try to import async logger for performance optimization
22
26
  try:
23
27
  from claude_mpm.services.async_session_logger import (
@@ -38,6 +42,9 @@ logger = get_logger(__name__)
38
42
  class ClaudeSessionLogger:
39
43
  """Simplified response logger for Claude Code sessions."""
40
44
 
45
+ _initialization_lock = Lock()
46
+ _initialized = False
47
+
41
48
  def __init__(
42
49
  self,
43
50
  base_dir: Optional[Path] = None,
@@ -52,29 +59,41 @@ class ClaudeSessionLogger:
52
59
  use_async: Use async logging if available. Overrides config.
53
60
  config: Configuration instance to use (creates new if not provided)
54
61
  """
55
- # Load configuration
56
- if config is None:
57
- config = Config()
58
- self.config = config
59
-
60
- # Get response logging configuration
61
- response_config = self.config.get("response_logging", {})
62
-
63
- # Determine base directory
64
- if base_dir is None:
65
- # Check configuration first
66
- base_dir = response_config.get("session_directory")
67
- if not base_dir:
68
- # Fall back to default response directory
69
- base_dir = ".claude-mpm/responses"
70
- base_dir = Path(base_dir)
71
-
72
- self.base_dir = Path(base_dir)
73
- self.base_dir.mkdir(parents=True, exist_ok=True)
62
+ # Use initialization flag to prevent duplicate setup
63
+ with self._initialization_lock:
64
+ if self._initialized and hasattr(self, "config"):
65
+ logger.debug("ClaudeSessionLogger already initialized, skipping setup")
66
+ return
67
+
68
+ # Load configuration
69
+ if config is None:
70
+ config = Config()
71
+ self.config = config
72
+
73
+ # Get response logging configuration
74
+ response_config = self.config.get("response_logging", {})
75
+
76
+ # Determine base directory
77
+ if base_dir is None:
78
+ # Check configuration first
79
+ base_dir = response_config.get("session_directory")
80
+ if not base_dir:
81
+ # Fall back to default response directory
82
+ base_dir = ".claude-mpm/responses"
83
+ base_dir = Path(base_dir)
84
+
85
+ self.base_dir = Path(base_dir)
86
+ self.base_dir.mkdir(parents=True, exist_ok=True)
87
+
88
+ # Use centralized SessionManager for session ID
89
+ session_manager = get_session_manager()
90
+ self.session_id = session_manager.get_session_id()
91
+ logger.debug(
92
+ f"ClaudeSessionLogger using session ID from SessionManager: {self.session_id}"
93
+ )
74
94
 
75
- # Try to get session ID from environment
76
- self.session_id = self._get_claude_session_id()
77
- self.response_counter = {} # Track response count per session
95
+ self.response_counter = {} # Track response count per session
96
+ self._initialized = True
78
97
 
79
98
  # Determine if we should use async logging
80
99
  if use_async is None:
@@ -106,49 +125,17 @@ class ClaudeSessionLogger:
106
125
  # Synchronize session IDs - use the one we already generated
107
126
  if self.session_id and hasattr(self._async_logger, "set_session_id"):
108
127
  self._async_logger.set_session_id(self.session_id)
109
- logger.info(
128
+ logger.debug(
110
129
  f"Using async logger with session ID: {self.session_id}"
111
130
  )
112
131
  else:
113
- logger.info("Using async logger for improved performance")
132
+ logger.debug("Using async logger for improved performance")
114
133
  except Exception as e:
115
134
  logger.warning(
116
135
  f"Failed to initialize async logger, falling back to sync: {e}"
117
136
  )
118
137
  self.use_async = False
119
138
 
120
- def _get_claude_session_id(self) -> Optional[str]:
121
- """
122
- Get the Claude Code session ID from environment.
123
-
124
- Returns:
125
- Session ID if available, None otherwise
126
- """
127
- # Claude Code may set various environment variables
128
- # Check common patterns
129
- session_id = None
130
-
131
- # Check for CLAUDE_SESSION_ID
132
- session_id = os.environ.get("CLAUDE_SESSION_ID")
133
-
134
- # Check for ANTHROPIC_SESSION_ID
135
- if not session_id:
136
- session_id = os.environ.get("ANTHROPIC_SESSION_ID")
137
-
138
- # Check for generic SESSION_ID
139
- if not session_id:
140
- session_id = os.environ.get("SESSION_ID")
141
-
142
- # Generate a default based on timestamp if nothing found
143
- if not session_id:
144
- # Use a timestamp-based session ID as fallback
145
- session_id = datetime.now(timezone.utc).strftime("%Y%m%d_%H%M%S")
146
- logger.info(f"Session ID: {session_id} (generated)")
147
- else:
148
- logger.info(f"Session ID: {session_id}")
149
-
150
- return session_id
151
-
152
139
  def _generate_filename(self, agent: Optional[str] = None) -> str:
153
140
  """
154
141
  Generate a flat filename with session ID, agent, and timestamp.
@@ -251,10 +238,15 @@ class ClaudeSessionLogger:
251
238
  """
252
239
  Manually set the session ID.
253
240
 
241
+ Note: This updates both the local session ID and the SessionManager.
242
+
254
243
  Args:
255
244
  session_id: The session ID to use
256
245
  """
257
246
  self.session_id = session_id
247
+ # Also update SessionManager to keep consistency
248
+ session_manager = get_session_manager()
249
+ session_manager.set_session_id(session_id)
258
250
  logger.info(f"Session ID set to: {session_id}")
259
251
 
260
252
  def get_session_path(self) -> Optional[Path]:
@@ -280,13 +272,16 @@ class ClaudeSessionLogger:
280
272
  return self.session_id is not None
281
273
 
282
274
 
283
- # Singleton instance for easy access
275
+ # Singleton instance with thread-safe initialization
284
276
  _logger_instance = None
277
+ _logger_lock = Lock()
285
278
 
286
279
 
287
280
  def get_session_logger(config: Optional[Config] = None) -> ClaudeSessionLogger:
288
281
  """
289
- Get the singleton session logger instance.
282
+ Get the singleton session logger instance with thread-safe initialization.
283
+
284
+ Uses double-checked locking pattern to ensure thread safety.
290
285
 
291
286
  Args:
292
287
  config: Optional configuration instance to use
@@ -295,9 +290,16 @@ def get_session_logger(config: Optional[Config] = None) -> ClaudeSessionLogger:
295
290
  The shared ClaudeSessionLogger instance
296
291
  """
297
292
  global _logger_instance
298
- if _logger_instance is None:
299
- _logger_instance = ClaudeSessionLogger(config=config)
300
- return _logger_instance
293
+
294
+ # Fast path - check without lock
295
+ if _logger_instance is not None:
296
+ return _logger_instance
297
+
298
+ # Slow path - acquire lock and double-check
299
+ with _logger_lock:
300
+ if _logger_instance is None:
301
+ _logger_instance = ClaudeSessionLogger(config=config)
302
+ return _logger_instance
301
303
 
302
304
 
303
305
  def log_response(