claude-mpm 3.7.8__py3-none-any.whl → 3.9.0__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 (100) hide show
  1. claude_mpm/VERSION +1 -1
  2. claude_mpm/agents/BASE_PM.md +0 -106
  3. claude_mpm/agents/INSTRUCTIONS.md +0 -96
  4. claude_mpm/agents/MEMORY.md +94 -0
  5. claude_mpm/agents/WORKFLOW.md +86 -0
  6. claude_mpm/agents/templates/code_analyzer.json +2 -2
  7. claude_mpm/agents/templates/data_engineer.json +1 -1
  8. claude_mpm/agents/templates/documentation.json +1 -1
  9. claude_mpm/agents/templates/engineer.json +1 -1
  10. claude_mpm/agents/templates/ops.json +1 -1
  11. claude_mpm/agents/templates/qa.json +1 -1
  12. claude_mpm/agents/templates/research.json +1 -1
  13. claude_mpm/agents/templates/security.json +1 -1
  14. claude_mpm/agents/templates/ticketing.json +3 -8
  15. claude_mpm/agents/templates/version_control.json +1 -1
  16. claude_mpm/agents/templates/web_qa.json +2 -2
  17. claude_mpm/agents/templates/web_ui.json +2 -2
  18. claude_mpm/cli/__init__.py +2 -2
  19. claude_mpm/cli/commands/__init__.py +2 -1
  20. claude_mpm/cli/commands/agents.py +8 -3
  21. claude_mpm/cli/commands/tickets.py +596 -19
  22. claude_mpm/cli/parser.py +217 -5
  23. claude_mpm/config/__init__.py +30 -39
  24. claude_mpm/config/socketio_config.py +8 -5
  25. claude_mpm/constants.py +13 -0
  26. claude_mpm/core/__init__.py +8 -18
  27. claude_mpm/core/cache.py +596 -0
  28. claude_mpm/core/claude_runner.py +166 -622
  29. claude_mpm/core/config.py +7 -3
  30. claude_mpm/core/constants.py +339 -0
  31. claude_mpm/core/container.py +548 -38
  32. claude_mpm/core/exceptions.py +392 -0
  33. claude_mpm/core/framework_loader.py +249 -93
  34. claude_mpm/core/interactive_session.py +479 -0
  35. claude_mpm/core/interfaces.py +424 -0
  36. claude_mpm/core/lazy.py +467 -0
  37. claude_mpm/core/logging_config.py +444 -0
  38. claude_mpm/core/oneshot_session.py +465 -0
  39. claude_mpm/core/optimized_agent_loader.py +485 -0
  40. claude_mpm/core/optimized_startup.py +490 -0
  41. claude_mpm/core/service_registry.py +52 -26
  42. claude_mpm/core/socketio_pool.py +162 -5
  43. claude_mpm/core/types.py +292 -0
  44. claude_mpm/core/typing_utils.py +477 -0
  45. claude_mpm/hooks/claude_hooks/hook_handler.py +213 -99
  46. claude_mpm/init.py +2 -1
  47. claude_mpm/services/__init__.py +78 -14
  48. claude_mpm/services/agent/__init__.py +24 -0
  49. claude_mpm/services/agent/deployment.py +2548 -0
  50. claude_mpm/services/agent/management.py +598 -0
  51. claude_mpm/services/agent/registry.py +813 -0
  52. claude_mpm/services/agents/deployment/agent_deployment.py +728 -308
  53. claude_mpm/services/agents/memory/agent_memory_manager.py +160 -4
  54. claude_mpm/services/async_session_logger.py +8 -3
  55. claude_mpm/services/communication/__init__.py +21 -0
  56. claude_mpm/services/communication/socketio.py +1933 -0
  57. claude_mpm/services/communication/websocket.py +479 -0
  58. claude_mpm/services/core/__init__.py +123 -0
  59. claude_mpm/services/core/base.py +247 -0
  60. claude_mpm/services/core/interfaces.py +951 -0
  61. claude_mpm/services/framework_claude_md_generator/__init__.py +10 -3
  62. claude_mpm/services/framework_claude_md_generator/deployment_manager.py +14 -11
  63. claude_mpm/services/framework_claude_md_generator/section_generators/todo_task_tools.py +23 -23
  64. claude_mpm/services/framework_claude_md_generator.py +3 -2
  65. claude_mpm/services/health_monitor.py +4 -3
  66. claude_mpm/services/hook_service.py +64 -4
  67. claude_mpm/services/infrastructure/__init__.py +21 -0
  68. claude_mpm/services/infrastructure/logging.py +202 -0
  69. claude_mpm/services/infrastructure/monitoring.py +893 -0
  70. claude_mpm/services/memory/indexed_memory.py +648 -0
  71. claude_mpm/services/project/__init__.py +21 -0
  72. claude_mpm/services/project/analyzer.py +864 -0
  73. claude_mpm/services/project/registry.py +608 -0
  74. claude_mpm/services/project_analyzer.py +95 -2
  75. claude_mpm/services/recovery_manager.py +15 -9
  76. claude_mpm/services/response_tracker.py +3 -5
  77. claude_mpm/services/socketio/__init__.py +25 -0
  78. claude_mpm/services/socketio/handlers/__init__.py +25 -0
  79. claude_mpm/services/socketio/handlers/base.py +121 -0
  80. claude_mpm/services/socketio/handlers/connection.py +198 -0
  81. claude_mpm/services/socketio/handlers/file.py +213 -0
  82. claude_mpm/services/socketio/handlers/git.py +723 -0
  83. claude_mpm/services/socketio/handlers/memory.py +27 -0
  84. claude_mpm/services/socketio/handlers/project.py +25 -0
  85. claude_mpm/services/socketio/handlers/registry.py +145 -0
  86. claude_mpm/services/socketio_client_manager.py +12 -7
  87. claude_mpm/services/socketio_server.py +156 -30
  88. claude_mpm/services/ticket_manager.py +172 -9
  89. claude_mpm/services/ticket_manager_di.py +1 -1
  90. claude_mpm/services/version_control/semantic_versioning.py +80 -7
  91. claude_mpm/services/version_control/version_parser.py +528 -0
  92. claude_mpm/utils/error_handler.py +1 -1
  93. claude_mpm/validation/agent_validator.py +27 -14
  94. claude_mpm/validation/frontmatter_validator.py +231 -0
  95. {claude_mpm-3.7.8.dist-info → claude_mpm-3.9.0.dist-info}/METADATA +38 -128
  96. {claude_mpm-3.7.8.dist-info → claude_mpm-3.9.0.dist-info}/RECORD +100 -59
  97. {claude_mpm-3.7.8.dist-info → claude_mpm-3.9.0.dist-info}/WHEEL +0 -0
  98. {claude_mpm-3.7.8.dist-info → claude_mpm-3.9.0.dist-info}/entry_points.txt +0 -0
  99. {claude_mpm-3.7.8.dist-info → claude_mpm-3.9.0.dist-info}/licenses/LICENSE +0 -0
  100. {claude_mpm-3.7.8.dist-info → claude_mpm-3.9.0.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,392 @@
1
+ """Centralized exception hierarchy for Claude MPM.
2
+
3
+ This module provides a comprehensive exception hierarchy for standardized error
4
+ handling across the codebase. Each exception class supports contextual information
5
+ for better debugging and error resolution.
6
+
7
+ Design Principles:
8
+ 1. Clear inheritance hierarchy with MPMError as the base
9
+ 2. Context support for debugging (optional dict with additional details)
10
+ 3. Helpful error messages with actionable guidance
11
+ 4. Backward compatibility with existing error handling
12
+ 5. Structured error data for programmatic handling
13
+
14
+ Usage:
15
+ from claude_mpm.core.exceptions import ConfigurationError, AgentDeploymentError
16
+
17
+ # With context for debugging
18
+ raise ConfigurationError(
19
+ "Invalid agent configuration",
20
+ context={"agent_id": "engineer", "field": "version", "value": "invalid"}
21
+ )
22
+
23
+ # Simple usage
24
+ raise AgentDeploymentError("Failed to deploy agent to .claude/agents directory")
25
+ """
26
+
27
+ from typing import Dict, Any, Optional, List
28
+ from pathlib import Path
29
+
30
+
31
+ class MPMError(Exception):
32
+ """Base exception class for all Claude MPM errors.
33
+
34
+ This base class provides common functionality for all MPM exceptions including
35
+ context storage for debugging and structured error representation.
36
+
37
+ Attributes:
38
+ message: Human-readable error message
39
+ context: Optional dictionary with additional debugging context
40
+ error_code: Machine-readable error code (defaults to class name in lowercase)
41
+ """
42
+
43
+ def __init__(self, message: str, context: Optional[Dict[str, Any]] = None):
44
+ """Initialize MPM error with message and optional context.
45
+
46
+ Args:
47
+ message: Human-readable error message
48
+ context: Optional dictionary with debugging context
49
+ """
50
+ super().__init__(message)
51
+ self.message = message
52
+ self.context = context or {}
53
+ self.error_code = self._generate_error_code()
54
+
55
+ def _generate_error_code(self) -> str:
56
+ """Generate error code from class name."""
57
+ # Convert class name from CamelCase to snake_case
58
+ name = self.__class__.__name__
59
+ # Remove 'Error' suffix if present
60
+ if name.endswith('Error'):
61
+ name = name[:-5]
62
+ # Special case for MPM acronym
63
+ if name == 'MPM':
64
+ return 'mpm'
65
+ # Convert to snake_case
66
+ import re
67
+ return re.sub(r'(?<!^)(?=[A-Z])', '_', name).lower()
68
+
69
+ def to_dict(self) -> Dict[str, Any]:
70
+ """Convert error to dictionary format for structured logging/handling.
71
+
72
+ Returns:
73
+ Dictionary with error type, code, message, and context
74
+ """
75
+ return {
76
+ "error_type": self.__class__.__name__,
77
+ "error_code": self.error_code,
78
+ "message": self.message,
79
+ "context": self.context
80
+ }
81
+
82
+ def __str__(self) -> str:
83
+ """String representation with context if available."""
84
+ if self.context:
85
+ context_str = ", ".join(f"{k}={v}" for k, v in self.context.items())
86
+ return f"{self.message} (context: {context_str})"
87
+ return self.message
88
+
89
+
90
+ class AgentDeploymentError(MPMError):
91
+ """Exception raised when agent deployment fails.
92
+
93
+ This error occurs during agent deployment to .claude/agents directory,
94
+ including template building, version checking, and file operations.
95
+
96
+ Common causes:
97
+ - Template file not found or invalid
98
+ - Permission issues with .claude/agents directory
99
+ - Version conflicts or migration failures
100
+ - YAML generation errors
101
+ """
102
+
103
+ def __init__(self, message: str, context: Optional[Dict[str, Any]] = None):
104
+ """Initialize agent deployment error.
105
+
106
+ Args:
107
+ message: Error message describing deployment failure
108
+ context: Optional context with agent_id, template_path, deployment_path, etc.
109
+ """
110
+ super().__init__(message, context)
111
+
112
+ # Add helpful guidance based on context
113
+ if context:
114
+ if 'agent_id' in context:
115
+ self.message = f"[Agent: {context['agent_id']}] {message}"
116
+ if 'template_path' in context and 'not found' in message.lower():
117
+ self.message += f"\nEnsure template exists at: {context['template_path']}"
118
+ if 'permission' in message.lower():
119
+ self.message += "\nCheck directory permissions for .claude/agents"
120
+
121
+
122
+ class ConfigurationError(MPMError):
123
+ """Exception raised when configuration validation fails.
124
+
125
+ This error occurs when configuration files are invalid, missing required
126
+ fields, or contain incompatible values.
127
+
128
+ Common causes:
129
+ - Missing required configuration fields
130
+ - Invalid data types or formats
131
+ - Configuration file not found
132
+ - Schema validation failures
133
+ - Incompatible configuration versions
134
+ """
135
+
136
+ def __init__(self, message: str, context: Optional[Dict[str, Any]] = None):
137
+ """Initialize configuration error.
138
+
139
+ Args:
140
+ message: Error message describing configuration issue
141
+ context: Optional context with config_file, field, expected_type, actual_value, etc.
142
+ """
143
+ super().__init__(message, context)
144
+
145
+ # Add helpful guidance based on context
146
+ if context:
147
+ if 'config_file' in context:
148
+ self.message = f"[Config: {context['config_file']}] {message}"
149
+ if 'field' in context:
150
+ self.message += f"\nField: {context['field']}"
151
+ if 'expected_type' in context:
152
+ self.message += f" (expected: {context['expected_type']})"
153
+ if 'actual_value' in context:
154
+ self.message += f" (got: {context['actual_value']})"
155
+
156
+
157
+ class ConnectionError(MPMError):
158
+ """Exception raised when network or SocketIO connection fails.
159
+
160
+ This error occurs during network operations, including SocketIO server
161
+ connections, port binding, and inter-process communication.
162
+
163
+ Common causes:
164
+ - Port already in use
165
+ - Network interface unavailable
166
+ - SocketIO server not responding
167
+ - Connection timeout
168
+ - Authentication failures
169
+ """
170
+
171
+ def __init__(self, message: str, context: Optional[Dict[str, Any]] = None):
172
+ """Initialize connection error.
173
+
174
+ Args:
175
+ message: Error message describing connection failure
176
+ context: Optional context with host, port, timeout, retry_count, etc.
177
+ """
178
+ super().__init__(message, context)
179
+
180
+ # Add helpful guidance based on context
181
+ if context:
182
+ if 'host' in context and 'port' in context:
183
+ self.message = f"[{context['host']}:{context['port']}] {message}"
184
+ if 'timeout' in context:
185
+ self.message += f"\nConnection timeout: {context['timeout']}s"
186
+ if 'retry_count' in context:
187
+ self.message += f"\nRetry attempts: {context['retry_count']}"
188
+
189
+
190
+ class ValidationError(MPMError):
191
+ """Exception raised when input validation fails.
192
+
193
+ This error occurs when user input, agent definitions, or data structures
194
+ fail validation against expected schemas or constraints.
195
+
196
+ Common causes:
197
+ - Invalid agent schema
198
+ - Missing required fields
199
+ - Type mismatches
200
+ - Value out of allowed range
201
+ - Format violations (e.g., invalid JSON/YAML)
202
+ """
203
+
204
+ def __init__(self, message: str, context: Optional[Dict[str, Any]] = None):
205
+ """Initialize validation error.
206
+
207
+ Args:
208
+ message: Error message describing validation failure
209
+ context: Optional context with field, value, constraint, schema_path, etc.
210
+ """
211
+ super().__init__(message, context)
212
+
213
+ # Add helpful guidance based on context
214
+ if context:
215
+ if 'field' in context:
216
+ self.message = f"[Field: {context['field']}] {message}"
217
+ if 'constraint' in context:
218
+ self.message += f"\nConstraint: {context['constraint']}"
219
+ if 'value' in context:
220
+ self.message += f"\nProvided value: {context['value']}"
221
+ if 'schema_path' in context:
222
+ self.message += f"\nSchema: {context['schema_path']}"
223
+
224
+
225
+ class ServiceNotFoundError(MPMError):
226
+ """Exception raised when DI container cannot find requested service.
227
+
228
+ This error occurs when the dependency injection container cannot locate
229
+ or instantiate a requested service.
230
+
231
+ Common causes:
232
+ - Service not registered in container
233
+ - Circular dependencies
234
+ - Missing service dependencies
235
+ - Service initialization failure
236
+ - Incorrect service name or type
237
+ """
238
+
239
+ def __init__(self, message: str, context: Optional[Dict[str, Any]] = None):
240
+ """Initialize service not found error.
241
+
242
+ Args:
243
+ message: Error message describing missing service
244
+ context: Optional context with service_name, service_type, available_services, etc.
245
+ """
246
+ super().__init__(message, context)
247
+
248
+ # Add helpful guidance based on context
249
+ if context:
250
+ if 'service_name' in context:
251
+ self.message = f"[Service: {context['service_name']}] {message}"
252
+ if 'available_services' in context:
253
+ services = context['available_services']
254
+ if isinstance(services, list) and services:
255
+ self.message += f"\nAvailable services: {', '.join(services[:5])}"
256
+ if len(services) > 5:
257
+ self.message += f" (and {len(services) - 5} more)"
258
+
259
+
260
+ class MemoryError(MPMError):
261
+ """Exception raised when memory service operations fail.
262
+
263
+ This error occurs during agent memory operations including storage,
264
+ retrieval, optimization, and routing.
265
+
266
+ Common causes:
267
+ - Memory storage failure
268
+ - Corrupted memory data
269
+ - Memory quota exceeded
270
+ - Routing configuration errors
271
+ - Serialization/deserialization failures
272
+
273
+ Note: This shadows Python's built-in MemoryError but is scoped to
274
+ claude_mpm.core.exceptions.MemoryError for clarity.
275
+ """
276
+
277
+ def __init__(self, message: str, context: Optional[Dict[str, Any]] = None):
278
+ """Initialize memory error.
279
+
280
+ Args:
281
+ message: Error message describing memory operation failure
282
+ context: Optional context with agent_id, memory_type, operation, storage_path, etc.
283
+ """
284
+ super().__init__(message, context)
285
+
286
+ # Add helpful guidance based on context
287
+ if context:
288
+ if 'agent_id' in context:
289
+ self.message = f"[Agent: {context['agent_id']}] {message}"
290
+ if 'memory_type' in context:
291
+ self.message += f"\nMemory type: {context['memory_type']}"
292
+ if 'operation' in context:
293
+ self.message += f"\nOperation: {context['operation']}"
294
+ if 'storage_path' in context:
295
+ self.message += f"\nStorage: {context['storage_path']}"
296
+
297
+
298
+ class HookError(MPMError):
299
+ """Exception raised when hook execution fails.
300
+
301
+ This error occurs during pre/post hook execution in the hook system,
302
+ including hook registration, invocation, and cleanup.
303
+
304
+ Common causes:
305
+ - Hook handler exceptions
306
+ - Hook timeout
307
+ - Missing hook dependencies
308
+ - Hook configuration errors
309
+ - Incompatible hook versions
310
+ """
311
+
312
+ def __init__(self, message: str, context: Optional[Dict[str, Any]] = None):
313
+ """Initialize hook error.
314
+
315
+ Args:
316
+ message: Error message describing hook failure
317
+ context: Optional context with hook_name, hook_type, event, error_details, etc.
318
+ """
319
+ super().__init__(message, context)
320
+
321
+ # Add helpful guidance based on context
322
+ if context:
323
+ if 'hook_name' in context:
324
+ self.message = f"[Hook: {context['hook_name']}] {message}"
325
+ if 'hook_type' in context:
326
+ self.message += f"\nType: {context['hook_type']}"
327
+ if 'event' in context:
328
+ self.message += f"\nEvent: {context['event']}"
329
+ if 'error_details' in context:
330
+ self.message += f"\nDetails: {context['error_details']}"
331
+
332
+
333
+ class SessionError(MPMError):
334
+ """Exception raised when session management fails.
335
+
336
+ This error occurs during Claude session lifecycle management including
337
+ session creation, state management, and cleanup.
338
+
339
+ Common causes:
340
+ - Session initialization failure
341
+ - Invalid session state
342
+ - Session timeout
343
+ - Resource allocation failure
344
+ - Session persistence errors
345
+ """
346
+
347
+ def __init__(self, message: str, context: Optional[Dict[str, Any]] = None):
348
+ """Initialize session error.
349
+
350
+ Args:
351
+ message: Error message describing session failure
352
+ context: Optional context with session_id, session_type, state, operation, etc.
353
+ """
354
+ super().__init__(message, context)
355
+
356
+ # Add helpful guidance based on context
357
+ if context:
358
+ if 'session_id' in context:
359
+ self.message = f"[Session: {context['session_id']}] {message}"
360
+ if 'session_type' in context:
361
+ self.message += f"\nType: {context['session_type']}"
362
+ if 'state' in context:
363
+ self.message += f"\nState: {context['state']}"
364
+ if 'operation' in context:
365
+ self.message += f"\nOperation: {context['operation']}"
366
+
367
+
368
+ # Backward compatibility imports
369
+ # These allow existing code to continue working while migrating to new exceptions
370
+ def create_agent_deployment_error(message: str, **kwargs) -> AgentDeploymentError:
371
+ """Factory function for creating agent deployment errors with context."""
372
+ return AgentDeploymentError(message, context=kwargs if kwargs else None)
373
+
374
+ def create_configuration_error(message: str, **kwargs) -> ConfigurationError:
375
+ """Factory function for creating configuration errors with context."""
376
+ return ConfigurationError(message, context=kwargs if kwargs else None)
377
+
378
+ def create_connection_error(message: str, **kwargs) -> ConnectionError:
379
+ """Factory function for creating connection errors with context."""
380
+ return ConnectionError(message, context=kwargs if kwargs else None)
381
+
382
+ def create_validation_error(message: str, **kwargs) -> ValidationError:
383
+ """Factory function for creating validation errors with context."""
384
+ return ValidationError(message, context=kwargs if kwargs else None)
385
+
386
+
387
+ # Exception groups for catch-all handling
388
+ DEPLOYMENT_ERRORS = (AgentDeploymentError,)
389
+ CONFIGURATION_ERRORS = (ConfigurationError, ValidationError)
390
+ NETWORK_ERRORS = (ConnectionError,)
391
+ SERVICE_ERRORS = (ServiceNotFoundError, MemoryError, HookError, SessionError)
392
+ ALL_MPM_ERRORS = (MPMError,) # Catches all MPM-specific exceptions