claude-mpm 3.1.2__py3-none-any.whl → 3.1.3__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 (38) hide show
  1. claude_mpm/__main__.py +17 -0
  2. claude_mpm/agents/INSTRUCTIONS.md +17 -2
  3. claude_mpm/cli/__init__.py +23 -14
  4. claude_mpm/cli/commands/agents.py +18 -7
  5. claude_mpm/cli/commands/info.py +10 -5
  6. claude_mpm/cli/commands/run.py +22 -7
  7. claude_mpm/cli/commands/tickets.py +17 -10
  8. claude_mpm/cli/commands/ui.py +37 -15
  9. claude_mpm/cli/utils.py +28 -9
  10. claude_mpm/core/agent_registry.py +4 -4
  11. claude_mpm/core/factories.py +1 -1
  12. claude_mpm/core/service_registry.py +1 -1
  13. claude_mpm/core/simple_runner.py +17 -27
  14. claude_mpm/hooks/claude_hooks/hook_handler.py +53 -4
  15. claude_mpm/models/__init__.py +91 -9
  16. claude_mpm/models/common.py +41 -0
  17. claude_mpm/models/lifecycle.py +97 -0
  18. claude_mpm/models/modification.py +126 -0
  19. claude_mpm/models/persistence.py +57 -0
  20. claude_mpm/models/registry.py +91 -0
  21. claude_mpm/security/__init__.py +8 -0
  22. claude_mpm/security/bash_validator.py +393 -0
  23. claude_mpm/services/agent_lifecycle_manager.py +25 -76
  24. claude_mpm/services/agent_modification_tracker.py +17 -98
  25. claude_mpm/services/agent_persistence_service.py +13 -33
  26. claude_mpm/services/agent_registry.py +43 -82
  27. claude_mpm/services/{ticketing_service_original.py → legacy_ticketing_service.py} +16 -9
  28. claude_mpm/services/ticket_manager.py +5 -4
  29. claude_mpm/services/{ticket_manager_di.py → ticket_manager_dependency_injection.py} +39 -12
  30. claude_mpm/services/version_control/semantic_versioning.py +10 -9
  31. claude_mpm/utils/path_operations.py +20 -0
  32. {claude_mpm-3.1.2.dist-info → claude_mpm-3.1.3.dist-info}/METADATA +9 -1
  33. {claude_mpm-3.1.2.dist-info → claude_mpm-3.1.3.dist-info}/RECORD +37 -31
  34. claude_mpm/utils/import_migration_example.py +0 -80
  35. {claude_mpm-3.1.2.dist-info → claude_mpm-3.1.3.dist-info}/WHEEL +0 -0
  36. {claude_mpm-3.1.2.dist-info → claude_mpm-3.1.3.dist-info}/entry_points.txt +0 -0
  37. {claude_mpm-3.1.2.dist-info → claude_mpm-3.1.3.dist-info}/licenses/LICENSE +0 -0
  38. {claude_mpm-3.1.2.dist-info → claude_mpm-3.1.3.dist-info}/top_level.txt +0 -0
@@ -1,24 +1,106 @@
1
1
  """
2
- Agent models package.
2
+ Claude MPM Models Package
3
+ =========================
3
4
 
4
- WHY: This package centralizes all data models used for agent management,
5
- providing a single source of truth for data structures across the system.
5
+ Centralized data models for the Claude MPM system.
6
+
7
+ WHY: This package centralizes all data models to:
8
+ - Prevent circular imports
9
+ - Reduce code duplication
10
+ - Ensure consistent data structures
11
+ - Make models easily discoverable
12
+
13
+ DESIGN DECISION: Models are organized by domain:
14
+ - agent_definition: Core agent behavior models
15
+ - lifecycle: Agent lifecycle management models
16
+ - modification: Change tracking models
17
+ - persistence: Storage operation models
18
+ - registry: Discovery and management models
19
+ - common: Shared constants and enums
6
20
  """
7
21
 
22
+ # Agent definition models
8
23
  from .agent_definition import (
9
- AgentDefinition,
10
- AgentMetadata,
11
24
  AgentType,
12
25
  AgentSection,
26
+ AgentPermissions,
13
27
  AgentWorkflow,
14
- AgentPermissions
28
+ AgentMetadata,
29
+ AgentDefinition
30
+ )
31
+
32
+ # Lifecycle models
33
+ from .lifecycle import (
34
+ LifecycleOperation,
35
+ LifecycleState,
36
+ AgentLifecycleRecord,
37
+ LifecycleOperationResult
38
+ )
39
+
40
+ # Modification models
41
+ from .modification import (
42
+ ModificationType,
43
+ ModificationTier,
44
+ AgentModification,
45
+ ModificationHistory
46
+ )
47
+
48
+ # Persistence models
49
+ from .persistence import (
50
+ PersistenceStrategy,
51
+ PersistenceOperation,
52
+ PersistenceRecord
53
+ )
54
+
55
+ # Registry models
56
+ from .registry import (
57
+ AgentTier,
58
+ AgentRegistryMetadata
59
+ )
60
+
61
+ # Common constants
62
+ from .common import (
63
+ AGENT_FILE_EXTENSIONS,
64
+ AGENT_IGNORE_PATTERNS,
65
+ CORE_AGENT_TYPES,
66
+ SPECIALIZED_AGENT_TYPES,
67
+ ALL_AGENT_TYPES
15
68
  )
16
69
 
17
70
  __all__ = [
18
- 'AgentDefinition',
19
- 'AgentMetadata',
71
+ # Agent definition
20
72
  'AgentType',
21
73
  'AgentSection',
74
+ 'AgentPermissions',
22
75
  'AgentWorkflow',
23
- 'AgentPermissions'
76
+ 'AgentMetadata',
77
+ 'AgentDefinition',
78
+
79
+ # Lifecycle
80
+ 'LifecycleOperation',
81
+ 'LifecycleState',
82
+ 'AgentLifecycleRecord',
83
+ 'LifecycleOperationResult',
84
+
85
+ # Modification
86
+ 'ModificationType',
87
+ 'ModificationTier',
88
+ 'AgentModification',
89
+ 'ModificationHistory',
90
+
91
+ # Persistence
92
+ 'PersistenceStrategy',
93
+ 'PersistenceOperation',
94
+ 'PersistenceRecord',
95
+
96
+ # Registry
97
+ 'AgentTier',
98
+ 'AgentRegistryMetadata',
99
+
100
+ # Common
101
+ 'AGENT_FILE_EXTENSIONS',
102
+ 'AGENT_IGNORE_PATTERNS',
103
+ 'CORE_AGENT_TYPES',
104
+ 'SPECIALIZED_AGENT_TYPES',
105
+ 'ALL_AGENT_TYPES'
24
106
  ]
@@ -0,0 +1,41 @@
1
+ #!/usr/bin/env python3
2
+ """
3
+ Common Models
4
+ =============
5
+
6
+ Shared enums and models used across multiple services.
7
+
8
+ WHY: This module contains enums and models that are used by multiple
9
+ services but don't belong to any specific domain.
10
+
11
+ DESIGN DECISION: Creating a common module prevents:
12
+ - Circular imports between specific model modules
13
+ - Duplication of shared enums
14
+ - Inconsistencies in shared constants
15
+ """
16
+
17
+ from enum import Enum
18
+
19
+
20
+ # Note: We're not creating a unified TierType enum here because:
21
+ # 1. ModificationTier uses PROJECT/USER/SYSTEM for modification tracking
22
+ # 2. AgentTier uses USER/SYSTEM for registry discovery
23
+ # 3. AgentType in agent_definition.py is for agent classification (CORE/PROJECT/CUSTOM/etc)
24
+ # These serve different purposes and should remain separate.
25
+
26
+ # Common constants that might be shared across services
27
+ AGENT_FILE_EXTENSIONS = {'.md', '.json', '.yaml', '.yml'}
28
+ AGENT_IGNORE_PATTERNS = {'__pycache__', '.git', 'node_modules', '.pytest_cache'}
29
+
30
+ # Core agent types used for classification
31
+ CORE_AGENT_TYPES = {
32
+ 'engineer', 'architect', 'qa', 'security', 'documentation',
33
+ 'ops', 'data', 'research', 'version_control'
34
+ }
35
+
36
+ SPECIALIZED_AGENT_TYPES = {
37
+ 'pm_orchestrator', 'frontend', 'backend', 'devops', 'ml',
38
+ 'database', 'api', 'mobile', 'cloud', 'testing'
39
+ }
40
+
41
+ ALL_AGENT_TYPES = CORE_AGENT_TYPES | SPECIALIZED_AGENT_TYPES
@@ -0,0 +1,97 @@
1
+ #!/usr/bin/env python3
2
+ """
3
+ Lifecycle Models
4
+ ================
5
+
6
+ Data models for agent lifecycle management.
7
+
8
+ WHY: These models are extracted from agent_lifecycle_manager.py to centralize
9
+ data definitions and reduce duplication across services.
10
+
11
+ DESIGN DECISION: Keeping lifecycle-specific models separate allows:
12
+ - Clear separation of concerns
13
+ - Easy reuse across different services
14
+ - Independent evolution of data structures
15
+ """
16
+
17
+ from dataclasses import dataclass, field
18
+ from datetime import datetime
19
+ from enum import Enum
20
+ from typing import Dict, List, Optional, Any
21
+
22
+ from claude_mpm.models.modification import ModificationTier
23
+
24
+
25
+ class LifecycleOperation(Enum):
26
+ """Agent lifecycle operations."""
27
+ CREATE = "create"
28
+ UPDATE = "update"
29
+ DELETE = "delete"
30
+ RESTORE = "restore"
31
+ MIGRATE = "migrate"
32
+ REPLICATE = "replicate"
33
+ VALIDATE = "validate"
34
+
35
+
36
+ class LifecycleState(Enum):
37
+ """Agent lifecycle states."""
38
+ ACTIVE = "active"
39
+ MODIFIED = "modified"
40
+ DELETED = "deleted"
41
+ CONFLICTED = "conflicted"
42
+ MIGRATING = "migrating"
43
+ VALIDATING = "validating"
44
+
45
+
46
+ @dataclass
47
+ class AgentLifecycleRecord:
48
+ """Complete lifecycle record for an agent.
49
+
50
+ WHY: This model tracks the complete history and state of an agent
51
+ throughout its lifecycle, enabling audit trails and state management.
52
+ """
53
+
54
+ agent_name: str
55
+ current_state: LifecycleState
56
+ tier: ModificationTier
57
+ file_path: str
58
+ created_at: float
59
+ last_modified: float
60
+ version: str
61
+ modifications: List[str] = field(default_factory=list) # Modification IDs
62
+ persistence_operations: List[str] = field(default_factory=list) # Operation IDs
63
+ backup_paths: List[str] = field(default_factory=list)
64
+ validation_status: str = "valid"
65
+ validation_errors: List[str] = field(default_factory=list)
66
+ metadata: Dict[str, Any] = field(default_factory=dict)
67
+
68
+ @property
69
+ def age_days(self) -> float:
70
+ """Get age in days."""
71
+ import time
72
+ return (time.time() - self.created_at) / (24 * 3600)
73
+
74
+ @property
75
+ def last_modified_datetime(self) -> datetime:
76
+ """Get last modified as datetime."""
77
+ return datetime.fromtimestamp(self.last_modified)
78
+
79
+
80
+ @dataclass
81
+ class LifecycleOperationResult:
82
+ """Result of a lifecycle operation.
83
+
84
+ WHY: Provides a consistent structure for operation results,
85
+ making it easier to track success/failure and gather metrics.
86
+ """
87
+
88
+ operation: LifecycleOperation
89
+ agent_name: str
90
+ success: bool
91
+ duration_ms: float
92
+ error_message: Optional[str] = None
93
+ modification_id: Optional[str] = None
94
+ persistence_id: Optional[str] = None
95
+ cache_invalidated: bool = False
96
+ registry_updated: bool = False
97
+ metadata: Dict[str, Any] = field(default_factory=dict)
@@ -0,0 +1,126 @@
1
+ #!/usr/bin/env python3
2
+ """
3
+ Modification Models
4
+ ===================
5
+
6
+ Data models for agent modification tracking.
7
+
8
+ WHY: These models are extracted from agent_modification_tracker.py to centralize
9
+ data definitions and enable reuse across services.
10
+
11
+ DESIGN DECISION: Modification tracking models are kept separate because:
12
+ - They represent a distinct domain (change tracking)
13
+ - Multiple services need to work with modifications
14
+ - The structure can evolve independently of other models
15
+ """
16
+
17
+ from dataclasses import dataclass, field, asdict
18
+ from datetime import datetime
19
+ from enum import Enum
20
+ from typing import Dict, List, Optional, Any
21
+ import time
22
+
23
+
24
+ class ModificationType(Enum):
25
+ """Types of agent modifications."""
26
+ CREATE = "create"
27
+ MODIFY = "modify"
28
+ DELETE = "delete"
29
+ MOVE = "move"
30
+ RESTORE = "restore"
31
+
32
+
33
+ class ModificationTier(Enum):
34
+ """Agent hierarchy tiers for modification tracking.
35
+
36
+ WHY: This enum is used across multiple services to ensure
37
+ consistent tier classification throughout the system.
38
+ """
39
+ PROJECT = "project"
40
+ USER = "user"
41
+ SYSTEM = "system"
42
+
43
+
44
+ @dataclass
45
+ class AgentModification:
46
+ """Agent modification record with comprehensive metadata.
47
+
48
+ WHY: This model captures all relevant information about a single
49
+ modification event, enabling detailed audit trails and rollback capabilities.
50
+ """
51
+
52
+ modification_id: str
53
+ agent_name: str
54
+ modification_type: ModificationType
55
+ tier: ModificationTier
56
+ file_path: str
57
+ timestamp: float
58
+ user_id: Optional[str] = None
59
+ modification_details: Dict[str, Any] = field(default_factory=dict)
60
+ file_hash_before: Optional[str] = None
61
+ file_hash_after: Optional[str] = None
62
+ file_size_before: Optional[int] = None
63
+ file_size_after: Optional[int] = None
64
+ backup_path: Optional[str] = None
65
+ validation_status: str = "pending"
66
+ validation_errors: List[str] = field(default_factory=list)
67
+ related_modifications: List[str] = field(default_factory=list)
68
+ metadata: Dict[str, Any] = field(default_factory=dict)
69
+
70
+ @property
71
+ def modification_datetime(self) -> datetime:
72
+ """Get modification timestamp as datetime."""
73
+ return datetime.fromtimestamp(self.timestamp)
74
+
75
+ @property
76
+ def age_seconds(self) -> float:
77
+ """Get age of modification in seconds."""
78
+ return time.time() - self.timestamp
79
+
80
+ def to_dict(self) -> Dict[str, Any]:
81
+ """Convert to dictionary for serialization."""
82
+ data = asdict(self)
83
+ data['modification_type'] = self.modification_type.value
84
+ data['tier'] = self.tier.value
85
+ return data
86
+
87
+ @classmethod
88
+ def from_dict(cls, data: Dict[str, Any]) -> 'AgentModification':
89
+ """Create from dictionary."""
90
+ data['modification_type'] = ModificationType(data['modification_type'])
91
+ data['tier'] = ModificationTier(data['tier'])
92
+ return cls(**data)
93
+
94
+
95
+ @dataclass
96
+ class ModificationHistory:
97
+ """Complete modification history for an agent.
98
+
99
+ WHY: Aggregates all modifications for a single agent, providing
100
+ a complete change history for analysis and rollback.
101
+ """
102
+
103
+ agent_name: str
104
+ modifications: List[AgentModification] = field(default_factory=list)
105
+ current_version: Optional[str] = None
106
+ total_modifications: int = 0
107
+ first_seen: Optional[float] = None
108
+ last_modified: Optional[float] = None
109
+
110
+ def add_modification(self, modification: AgentModification) -> None:
111
+ """Add a modification to history."""
112
+ self.modifications.append(modification)
113
+ self.total_modifications += 1
114
+ self.last_modified = modification.timestamp
115
+
116
+ if self.first_seen is None:
117
+ self.first_seen = modification.timestamp
118
+
119
+ def get_recent_modifications(self, hours: int = 24) -> List[AgentModification]:
120
+ """Get modifications within specified hours."""
121
+ cutoff = time.time() - (hours * 3600)
122
+ return [mod for mod in self.modifications if mod.timestamp >= cutoff]
123
+
124
+ def get_modifications_by_type(self, mod_type: ModificationType) -> List[AgentModification]:
125
+ """Get modifications by type."""
126
+ return [mod for mod in self.modifications if mod.modification_type == mod_type]
@@ -0,0 +1,57 @@
1
+ #!/usr/bin/env python3
2
+ """
3
+ Persistence Models
4
+ ==================
5
+
6
+ Data models for agent persistence operations.
7
+
8
+ WHY: These models are extracted from agent_persistence_service.py to centralize
9
+ data definitions and maintain consistency across services.
10
+
11
+ DESIGN DECISION: Persistence models are minimal because actual persistence
12
+ is now handled by AgentManager, but we maintain these for API compatibility.
13
+ """
14
+
15
+ from dataclasses import dataclass, field
16
+ from enum import Enum
17
+ from typing import Optional, Any, Dict
18
+
19
+
20
+ class PersistenceStrategy(Enum):
21
+ """Agent persistence strategies.
22
+
23
+ WHY: Different strategies allow flexibility in how agents are persisted
24
+ based on their tier and use case.
25
+ """
26
+ USER_OVERRIDE = "user_override"
27
+ PROJECT_SPECIFIC = "project_specific"
28
+ SYSTEM_DEFAULT = "system_default"
29
+
30
+
31
+ class PersistenceOperation(Enum):
32
+ """Persistence operation types."""
33
+ CREATE = "create"
34
+ UPDATE = "update"
35
+ DELETE = "delete"
36
+ BACKUP = "backup"
37
+ RESTORE = "restore"
38
+
39
+
40
+ @dataclass
41
+ class PersistenceRecord:
42
+ """Record of a persistence operation.
43
+
44
+ WHY: Tracks persistence operations for audit trails and debugging,
45
+ even though actual persistence is delegated to AgentManager.
46
+ """
47
+ operation_id: str
48
+ operation_type: PersistenceOperation
49
+ agent_name: str
50
+ source_tier: Any # Can be ModificationTier or string
51
+ target_tier: Optional[Any] = None
52
+ strategy: Optional[PersistenceStrategy] = None
53
+ success: bool = True
54
+ timestamp: float = 0.0
55
+ file_path: Optional[str] = None
56
+ error_message: Optional[str] = None
57
+ metadata: Dict[str, Any] = field(default_factory=dict)
@@ -0,0 +1,91 @@
1
+ #!/usr/bin/env python3
2
+ """
3
+ Registry Models
4
+ ===============
5
+
6
+ Data models for agent registry and discovery.
7
+
8
+ WHY: These models are extracted from agent_registry.py to centralize
9
+ data definitions and avoid duplication with agent_definition.py models.
10
+
11
+ DESIGN DECISION: Registry models are kept separate from agent definitions
12
+ because they serve different purposes:
13
+ - Registry models are for discovery and management
14
+ - Agent definitions are for execution and behavior
15
+ """
16
+
17
+ from dataclasses import dataclass, field, asdict
18
+ from enum import Enum
19
+ from typing import Dict, List, Any, Optional
20
+ import time
21
+
22
+
23
+ class AgentTier(Enum):
24
+ """Agent hierarchy tiers for registry.
25
+
26
+ WHY: Different from ModificationTier because registry uses a
27
+ simpler two-tier system (user/system) for discovery.
28
+ """
29
+ USER = "user"
30
+ SYSTEM = "system"
31
+
32
+
33
+ @dataclass
34
+ class AgentRegistryMetadata:
35
+ """Registry-specific metadata for discovered agents.
36
+
37
+ WHY: This is different from AgentMetadata in agent_definition.py because:
38
+ - Registry needs discovery-specific information (path, checksum, etc.)
39
+ - Agent definitions need behavior-specific information
40
+ - Keeping them separate avoids coupling discovery to execution
41
+
42
+ NOTE: This replaces the AgentMetadata class in agent_registry.py to avoid
43
+ conflicts with the one in agent_definition.py
44
+ """
45
+ name: str
46
+ path: str
47
+ tier: AgentTier
48
+ agent_type: str # Using string instead of AgentType enum to avoid conflicts
49
+ description: str = ""
50
+ version: str = "0.0.0"
51
+ dependencies: List[str] = field(default_factory=list)
52
+ capabilities: List[str] = field(default_factory=list)
53
+ created_at: float = field(default_factory=time.time)
54
+ last_modified: float = field(default_factory=time.time)
55
+ file_size: int = 0
56
+ checksum: str = ""
57
+ is_valid: bool = True
58
+ validation_errors: List[str] = field(default_factory=list)
59
+ metadata: Dict[str, Any] = field(default_factory=dict)
60
+
61
+ # Compatibility properties for existing code
62
+ @property
63
+ def type(self) -> str:
64
+ """Compatibility property for existing code expecting 'type' attribute."""
65
+ return self.agent_type
66
+
67
+ @property
68
+ def validated(self) -> bool:
69
+ """Compatibility property for existing code expecting 'validated' attribute."""
70
+ return self.is_valid
71
+
72
+ def to_dict(self) -> Dict[str, Any]:
73
+ """Convert to dictionary for serialization."""
74
+ data = asdict(self)
75
+ data['tier'] = self.tier.value
76
+ # Include compatibility fields
77
+ data['type'] = self.agent_type
78
+ data['validated'] = self.is_valid
79
+ return data
80
+
81
+ @classmethod
82
+ def from_dict(cls, data: Dict[str, Any]) -> 'AgentRegistryMetadata':
83
+ """Create from dictionary."""
84
+ # Handle compatibility fields
85
+ if 'type' in data and 'agent_type' not in data:
86
+ data['agent_type'] = data['type']
87
+ if 'validated' in data and 'is_valid' not in data:
88
+ data['is_valid'] = data['validated']
89
+
90
+ data['tier'] = AgentTier(data['tier'])
91
+ return cls(**data)
@@ -0,0 +1,8 @@
1
+ """Security module for claude-mpm.
2
+
3
+ Provides security validation and enforcement for agent operations.
4
+ """
5
+
6
+ from .bash_validator import BashSecurityValidator, create_validator
7
+
8
+ __all__ = ['BashSecurityValidator', 'create_validator']