claude-mpm 4.1.4__py3-none-any.whl → 4.1.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.
Files changed (81) hide show
  1. claude_mpm/VERSION +1 -1
  2. claude_mpm/agents/templates/research.json +39 -13
  3. claude_mpm/cli/__init__.py +2 -0
  4. claude_mpm/cli/commands/__init__.py +2 -0
  5. claude_mpm/cli/commands/configure.py +1221 -0
  6. claude_mpm/cli/commands/configure_tui.py +1921 -0
  7. claude_mpm/cli/commands/tickets.py +365 -784
  8. claude_mpm/cli/parsers/base_parser.py +7 -0
  9. claude_mpm/cli/parsers/configure_parser.py +119 -0
  10. claude_mpm/cli/startup_logging.py +39 -12
  11. claude_mpm/constants.py +1 -0
  12. claude_mpm/core/output_style_manager.py +24 -0
  13. claude_mpm/core/socketio_pool.py +35 -3
  14. claude_mpm/core/unified_agent_registry.py +46 -15
  15. claude_mpm/dashboard/static/css/connection-status.css +370 -0
  16. claude_mpm/dashboard/static/js/components/connection-debug.js +654 -0
  17. claude_mpm/dashboard/static/js/connection-manager.js +536 -0
  18. claude_mpm/dashboard/templates/index.html +11 -0
  19. claude_mpm/hooks/claude_hooks/services/__init__.py +3 -1
  20. claude_mpm/hooks/claude_hooks/services/connection_manager_http.py +190 -0
  21. claude_mpm/services/agents/deployment/agent_discovery_service.py +12 -3
  22. claude_mpm/services/agents/deployment/agent_lifecycle_manager.py +172 -233
  23. claude_mpm/services/agents/deployment/agent_lifecycle_manager_refactored.py +575 -0
  24. claude_mpm/services/agents/deployment/agent_operation_service.py +573 -0
  25. claude_mpm/services/agents/deployment/agent_record_service.py +419 -0
  26. claude_mpm/services/agents/deployment/agent_state_service.py +381 -0
  27. claude_mpm/services/agents/deployment/multi_source_deployment_service.py +4 -2
  28. claude_mpm/services/diagnostics/checks/__init__.py +2 -0
  29. claude_mpm/services/diagnostics/checks/instructions_check.py +418 -0
  30. claude_mpm/services/diagnostics/diagnostic_runner.py +15 -2
  31. claude_mpm/services/event_bus/direct_relay.py +173 -0
  32. claude_mpm/services/infrastructure/__init__.py +31 -5
  33. claude_mpm/services/infrastructure/monitoring/__init__.py +43 -0
  34. claude_mpm/services/infrastructure/monitoring/aggregator.py +437 -0
  35. claude_mpm/services/infrastructure/monitoring/base.py +130 -0
  36. claude_mpm/services/infrastructure/monitoring/legacy.py +203 -0
  37. claude_mpm/services/infrastructure/monitoring/network.py +218 -0
  38. claude_mpm/services/infrastructure/monitoring/process.py +342 -0
  39. claude_mpm/services/infrastructure/monitoring/resources.py +243 -0
  40. claude_mpm/services/infrastructure/monitoring/service.py +367 -0
  41. claude_mpm/services/infrastructure/monitoring.py +67 -1030
  42. claude_mpm/services/project/analyzer.py +13 -4
  43. claude_mpm/services/project/analyzer_refactored.py +450 -0
  44. claude_mpm/services/project/analyzer_v2.py +566 -0
  45. claude_mpm/services/project/architecture_analyzer.py +461 -0
  46. claude_mpm/services/project/dependency_analyzer.py +462 -0
  47. claude_mpm/services/project/language_analyzer.py +265 -0
  48. claude_mpm/services/project/metrics_collector.py +410 -0
  49. claude_mpm/services/socketio/handlers/connection_handler.py +345 -0
  50. claude_mpm/services/socketio/server/broadcaster.py +32 -1
  51. claude_mpm/services/socketio/server/connection_manager.py +516 -0
  52. claude_mpm/services/socketio/server/core.py +63 -0
  53. claude_mpm/services/socketio/server/eventbus_integration.py +20 -9
  54. claude_mpm/services/socketio/server/main.py +27 -1
  55. claude_mpm/services/ticket_manager.py +5 -1
  56. claude_mpm/services/ticket_services/__init__.py +26 -0
  57. claude_mpm/services/ticket_services/crud_service.py +328 -0
  58. claude_mpm/services/ticket_services/formatter_service.py +290 -0
  59. claude_mpm/services/ticket_services/search_service.py +324 -0
  60. claude_mpm/services/ticket_services/validation_service.py +303 -0
  61. claude_mpm/services/ticket_services/workflow_service.py +244 -0
  62. {claude_mpm-4.1.4.dist-info → claude_mpm-4.1.6.dist-info}/METADATA +3 -1
  63. {claude_mpm-4.1.4.dist-info → claude_mpm-4.1.6.dist-info}/RECORD +67 -46
  64. claude_mpm/agents/OUTPUT_STYLE.md +0 -73
  65. claude_mpm/agents/backups/INSTRUCTIONS.md +0 -352
  66. claude_mpm/agents/templates/OPTIMIZATION_REPORT.md +0 -156
  67. claude_mpm/agents/templates/backup/data_engineer_agent_20250726_234551.json +0 -79
  68. claude_mpm/agents/templates/backup/documentation_agent_20250726_234551.json +0 -68
  69. claude_mpm/agents/templates/backup/engineer_agent_20250726_234551.json +0 -77
  70. claude_mpm/agents/templates/backup/ops_agent_20250726_234551.json +0 -78
  71. claude_mpm/agents/templates/backup/qa_agent_20250726_234551.json +0 -67
  72. claude_mpm/agents/templates/backup/research_agent_2025011_234551.json +0 -88
  73. claude_mpm/agents/templates/backup/research_agent_20250726_234551.json +0 -72
  74. claude_mpm/agents/templates/backup/research_memory_efficient.json +0 -88
  75. claude_mpm/agents/templates/backup/security_agent_20250726_234551.json +0 -78
  76. claude_mpm/agents/templates/backup/version_control_agent_20250726_234551.json +0 -62
  77. claude_mpm/agents/templates/vercel_ops_instructions.md +0 -582
  78. {claude_mpm-4.1.4.dist-info → claude_mpm-4.1.6.dist-info}/WHEEL +0 -0
  79. {claude_mpm-4.1.4.dist-info → claude_mpm-4.1.6.dist-info}/entry_points.txt +0 -0
  80. {claude_mpm-4.1.4.dist-info → claude_mpm-4.1.6.dist-info}/licenses/LICENSE +0 -0
  81. {claude_mpm-4.1.4.dist-info → claude_mpm-4.1.6.dist-info}/top_level.txt +0 -0
@@ -1,14 +1,18 @@
1
- from pathlib import Path
2
-
3
1
  #!/usr/bin/env python3
4
2
  """
5
- Agent Lifecycle Manager - ISS-0118 Integration Service
6
- ======================================================
3
+ Agent Lifecycle Manager - ISS-0118 Integration Service (Refactored)
4
+ ===================================================================
7
5
 
8
6
  Comprehensive agent lifecycle management integrating modification tracking,
9
7
  persistence, and registry services for complete agent management across
10
8
  the three-tier hierarchy.
11
9
 
10
+ This refactored version delegates responsibilities to specialized services:
11
+ - AgentStateService: State tracking and transitions
12
+ - AgentOperationService: CRUD operations
13
+ - AgentRecordService: Persistence and history
14
+ - LifecycleHealthChecker: Health monitoring
15
+
12
16
  Key Features:
13
17
  - Unified agent lifecycle management (create, modify, delete, restore)
14
18
  - Integrated modification tracking and persistence
@@ -28,13 +32,10 @@ Created for ISS-0118: Agent Registry and Hierarchical Discovery System
28
32
 
29
33
  import asyncio
30
34
  import time
31
- from dataclasses import dataclass, field
32
- from datetime import datetime
33
- from enum import Enum
35
+ from pathlib import Path
34
36
  from typing import Any, Dict, List, Optional
35
37
 
36
38
  from claude_mpm.core.base_service import BaseService
37
- from claude_mpm.core.unified_paths import get_path_manager
38
39
  from claude_mpm.models.agent_definition import AgentDefinition
39
40
  from claude_mpm.services.agents.management import AgentManager
40
41
  from claude_mpm.services.agents.memory import (
@@ -51,82 +52,41 @@ from claude_mpm.services.agents.registry.modification_tracker import (
51
52
  ModificationType,
52
53
  )
53
54
  from claude_mpm.services.memory.cache.shared_prompt_cache import SharedPromptCache
54
- from claude_mpm.utils.config_manager import ConfigurationManager
55
55
  from claude_mpm.utils.path_operations import path_ops
56
56
 
57
+ # Import extracted services
58
+ from .agent_operation_service import (
59
+ AgentOperationService,
60
+ LifecycleOperation,
61
+ LifecycleOperationResult,
62
+ )
63
+ from .agent_record_service import AgentRecordService
64
+ from .agent_state_service import (
65
+ AgentLifecycleRecord,
66
+ AgentStateService,
67
+ LifecycleState,
68
+ )
57
69
 
58
- class LifecycleOperation(Enum):
59
- """Agent lifecycle operations."""
60
-
61
- CREATE = "create"
62
- UPDATE = "update"
63
- DELETE = "delete"
64
- RESTORE = "restore"
65
- MIGRATE = "migrate"
66
- REPLICATE = "replicate"
67
- VALIDATE = "validate"
68
-
69
-
70
- class LifecycleState(Enum):
71
- """Agent lifecycle states."""
72
-
73
- ACTIVE = "active"
74
- MODIFIED = "modified"
75
- DELETED = "deleted"
76
- CONFLICTED = "conflicted"
77
- MIGRATING = "migrating"
78
- VALIDATING = "validating"
79
-
80
-
81
- @dataclass
82
- class AgentLifecycleRecord:
83
- """Complete lifecycle record for an agent."""
84
-
85
- agent_name: str
86
- current_state: LifecycleState
87
- tier: ModificationTier
88
- file_path: str
89
- created_at: float
90
- last_modified: float
91
- version: str
92
- modifications: List[str] = field(default_factory=list) # Modification IDs
93
- persistence_operations: List[str] = field(default_factory=list) # Operation IDs
94
- backup_paths: List[str] = field(default_factory=list)
95
- validation_status: str = "valid"
96
- validation_errors: List[str] = field(default_factory=list)
97
- metadata: Dict[str, Any] = field(default_factory=dict)
98
-
99
- @property
100
- def age_days(self) -> float:
101
- """Get age in days."""
102
- return (time.time() - self.created_at) / (24 * 3600)
103
-
104
- @property
105
- def last_modified_datetime(self) -> datetime:
106
- """Get last modified as datetime."""
107
- return datetime.fromtimestamp(self.last_modified)
108
-
109
-
110
- @dataclass
111
- class LifecycleOperationResult:
112
- """Result of a lifecycle operation."""
113
-
114
- operation: LifecycleOperation
115
- agent_name: str
116
- success: bool
117
- duration_ms: float
118
- error_message: Optional[str] = None
119
- modification_id: Optional[str] = None
120
- persistence_id: Optional[str] = None
121
- cache_invalidated: bool = False
122
- registry_updated: bool = False
123
- metadata: Dict[str, Any] = field(default_factory=dict)
70
+ # Re-export for backward compatibility
71
+ __all__ = [
72
+ "AgentLifecycleManager",
73
+ "AgentLifecycleRecord",
74
+ "LifecycleOperation",
75
+ "LifecycleOperationResult",
76
+ "LifecycleState",
77
+ ]
124
78
 
125
79
 
126
80
  class AgentLifecycleManager(BaseService):
127
81
  """
128
82
  Agent Lifecycle Manager - Unified agent management across hierarchy tiers.
129
83
 
84
+ Refactored to use specialized services following SOLID principles:
85
+ - AgentStateService handles state tracking
86
+ - AgentOperationService handles CRUD operations
87
+ - AgentRecordService handles persistence
88
+ - LifecycleHealthChecker handles health monitoring
89
+
130
90
  Features:
131
91
  - Complete agent lifecycle management (CRUD operations)
132
92
  - Integrated modification tracking and persistence
@@ -153,17 +113,20 @@ class AgentLifecycleManager(BaseService):
153
113
  )
154
114
  )
155
115
 
156
- # Core services
116
+ # Core external services
157
117
  self.shared_cache: Optional[SharedPromptCache] = None
158
118
  self.agent_registry: Optional[AgentRegistry] = None
159
119
  self.modification_tracker: Optional[AgentModificationTracker] = None
160
120
  self.persistence_service: Optional[AgentPersistenceService] = None
161
121
  self.agent_manager: Optional[AgentManager] = None
162
122
 
163
- # Lifecycle tracking
164
- self.agent_records: Dict[str, AgentLifecycleRecord] = {}
165
- self.operation_history: List[LifecycleOperationResult] = []
166
- self.active_operations: Dict[str, LifecycleOperation] = {}
123
+ # Extracted internal services
124
+ self.state_service = AgentStateService()
125
+ self.operation_service = AgentOperationService()
126
+ self.record_service = AgentRecordService()
127
+
128
+ # Backward compatibility - expose service data through properties
129
+ self._operation_lock = asyncio.Lock()
167
130
 
168
131
  # Performance metrics
169
132
  self.performance_metrics = {
@@ -174,13 +137,7 @@ class AgentLifecycleManager(BaseService):
174
137
  "cache_hit_rate": 0.0,
175
138
  }
176
139
 
177
- # Operation lock for thread safety
178
- self._operation_lock = asyncio.Lock()
179
-
180
- # Configuration manager
181
- self.config_mgr = ConfigurationManager(cache_enabled=True)
182
-
183
- self.logger.info("AgentLifecycleManager initialized")
140
+ self.logger.info("AgentLifecycleManager initialized (refactored)")
184
141
 
185
142
  async def _initialize(self) -> None:
186
143
  """Initialize the lifecycle manager."""
@@ -189,8 +146,18 @@ class AgentLifecycleManager(BaseService):
189
146
  # Initialize core services
190
147
  await self._initialize_core_services()
191
148
 
192
- # Load existing agent records
193
- await self._load_agent_records()
149
+ # Initialize extracted services
150
+ await self.state_service.start()
151
+ await self.operation_service.start()
152
+ await self.record_service.start()
153
+
154
+ # Load existing agent records into state service
155
+ records = await self.record_service.load_records()
156
+ self.state_service.agent_records = records
157
+
158
+ # Setup operation service dependencies
159
+ self.operation_service.agent_manager = self.agent_manager
160
+ self.operation_service.set_modification_tracker(self.modification_tracker)
194
161
 
195
162
  # Start service integrations
196
163
  await self._setup_service_integrations()
@@ -205,8 +172,14 @@ class AgentLifecycleManager(BaseService):
205
172
  """Cleanup lifecycle manager resources."""
206
173
  self.logger.info("Cleaning up AgentLifecycleManager...")
207
174
 
208
- # Save agent records
209
- await self._save_agent_records()
175
+ # Save agent records through record service
176
+ await self.record_service.save_records(self.state_service.agent_records)
177
+ await self.record_service.save_history(self.operation_service.operation_history)
178
+
179
+ # Stop extracted services
180
+ await self.state_service.stop()
181
+ await self.operation_service.stop()
182
+ await self.record_service.stop()
210
183
 
211
184
  # Stop core services if we own them
212
185
  await self._cleanup_core_services()
@@ -260,26 +233,20 @@ class AgentLifecycleManager(BaseService):
260
233
  except Exception as e:
261
234
  self.logger.warning(f"Failed to setup some service integrations: {e}")
262
235
 
263
- async def _load_agent_records(self) -> None:
264
- """Load existing agent lifecycle records."""
265
- try:
266
- records_file = (
267
- get_path_manager().get_tracking_dir() / "lifecycle_records.json"
268
- )
269
- if path_ops.validate_exists(records_file):
270
- data = self.config_mgr.load_json(records_file)
271
-
272
- for agent_name, record_data in data.items():
273
- record = AgentLifecycleRecord(**record_data)
274
- # Convert string enum back to enum
275
- record.current_state = LifecycleState(record_data["current_state"])
276
- record.tier = ModificationTier(record_data["tier"])
277
- self.agent_records[agent_name] = record
236
+ @property
237
+ def agent_records(self) -> Dict[str, AgentLifecycleRecord]:
238
+ """Get agent records from state service (backward compatibility)."""
239
+ return self.state_service.agent_records
278
240
 
279
- self.logger.info(f"Loaded {len(self.agent_records)} agent records")
241
+ @property
242
+ def operation_history(self) -> List[LifecycleOperationResult]:
243
+ """Get operation history from operation service (backward compatibility)."""
244
+ return self.operation_service.operation_history
280
245
 
281
- except Exception as e:
282
- self.logger.warning(f"Failed to load agent records: {e}")
246
+ @property
247
+ def active_operations(self) -> Dict[str, LifecycleOperation]:
248
+ """Get active operations from operation service (backward compatibility)."""
249
+ return self.operation_service.active_operations
283
250
 
284
251
  async def _save_agent_records(self) -> None:
285
252
  """Save agent lifecycle records to disk."""
@@ -377,141 +344,113 @@ class AgentLifecycleManager(BaseService):
377
344
  """
378
345
  start_time = time.time()
379
346
 
380
- async with self._operation_lock:
381
- self.active_operations[agent_name] = LifecycleOperation.CREATE
382
-
383
- try:
384
- # Check if agent already exists
385
- if agent_name in self.agent_records:
386
- return LifecycleOperationResult(
387
- operation=LifecycleOperation.CREATE,
388
- agent_name=agent_name,
389
- success=False,
390
- duration_ms=(time.time() - start_time) * 1000,
391
- error_message="Agent already exists",
392
- )
393
-
394
- # Create agent definition
395
- agent_def = await self._create_agent_definition(
396
- agent_name, agent_content, tier, agent_type, **kwargs
397
- )
398
-
399
- # Determine location based on tier
400
- location = (
401
- "project" if tier == ModificationTier.PROJECT else "framework"
402
- )
403
-
404
- # Create agent using AgentManager (sync call in executor)
405
- try:
406
- if self.agent_manager:
407
- file_path = await self._run_sync_in_executor(
408
- self.agent_manager.create_agent,
409
- agent_name,
410
- agent_def,
411
- location,
412
- )
413
- else:
414
- # Fallback to direct file creation if AgentManager not available
415
- file_path = await self._determine_agent_file_path(
416
- agent_name, tier
417
- )
418
- path_ops.ensure_dir(file_path.parent)
419
- path_ops.safe_write(file_path, agent_content)
420
- except Exception as e:
421
- self.logger.error(f"AgentManager failed to create agent: {e}")
422
- # Fallback to direct file creation
423
- file_path = await self._determine_agent_file_path(agent_name, tier)
424
- path_ops.ensure_dir(file_path.parent)
425
- path_ops.safe_write(file_path, agent_content)
426
-
427
- # Track modification
428
- modification = await self.modification_tracker.track_modification(
429
- agent_name=agent_name,
430
- modification_type=ModificationType.CREATE,
431
- file_path=str(file_path),
432
- tier=tier,
433
- agent_type=agent_type,
434
- **kwargs,
435
- )
436
-
437
- # Note: We don't use persistence_service for the actual write anymore
438
- # since AgentManager handles that. We create a synthetic record for compatibility.
439
- persistence_record = PersistenceRecord(
440
- operation_id=f"create_{agent_name}_{time.time()}",
441
- operation_type=PersistenceOperation.CREATE,
442
- agent_name=agent_name,
443
- source_tier=tier,
444
- target_tier=tier,
445
- strategy=self.default_persistence_strategy,
446
- success=True,
447
- timestamp=time.time(),
448
- file_path=str(file_path),
449
- )
450
-
451
- # Create lifecycle record
452
- lifecycle_record = AgentLifecycleRecord(
453
- agent_name=agent_name,
454
- current_state=LifecycleState.ACTIVE,
455
- tier=tier,
456
- file_path=str(file_path),
457
- created_at=time.time(),
458
- last_modified=time.time(),
459
- version="1.0.0",
460
- modifications=[modification.modification_id],
461
- persistence_operations=[persistence_record.operation_id],
462
- metadata={"agent_type": agent_type, **kwargs},
463
- )
347
+ # Check if agent already exists
348
+ if self.state_service.get_record(agent_name):
349
+ return LifecycleOperationResult(
350
+ operation=LifecycleOperation.CREATE,
351
+ agent_name=agent_name,
352
+ success=False,
353
+ duration_ms=0,
354
+ error_message="Agent already exists",
355
+ )
464
356
 
465
- self.agent_records[agent_name] = lifecycle_record
357
+ # Create agent definition
358
+ agent_def = await self._create_agent_definition(
359
+ agent_name, agent_content, tier, agent_type, **kwargs
360
+ )
466
361
 
467
- # Invalidate cache and update registry
468
- cache_invalidated = await self._invalidate_agent_cache(agent_name)
469
- registry_updated = await self._update_registry(agent_name)
362
+ # Determine location based on tier
363
+ location = "project" if tier == ModificationTier.PROJECT else "framework"
470
364
 
471
- # Create result
472
- result = LifecycleOperationResult(
473
- operation=LifecycleOperation.CREATE,
474
- agent_name=agent_name,
475
- success=persistence_record.success,
476
- duration_ms=(time.time() - start_time) * 1000,
477
- modification_id=modification.modification_id,
478
- persistence_id=persistence_record.operation_id,
479
- cache_invalidated=cache_invalidated,
480
- registry_updated=registry_updated,
481
- metadata={"file_path": str(file_path)},
365
+ # Create agent using AgentManager (sync call in executor)
366
+ try:
367
+ if self.agent_manager:
368
+ file_path = await self._run_sync_in_executor(
369
+ self.agent_manager.create_agent,
370
+ agent_name,
371
+ agent_def,
372
+ location,
482
373
  )
374
+ else:
375
+ # Fallback to direct file creation if AgentManager not available
376
+ file_path = await self._determine_agent_file_path(agent_name, tier)
377
+ path_ops.ensure_dir(file_path.parent)
378
+ path_ops.safe_write(file_path, agent_content)
379
+ except Exception as e:
380
+ self.logger.error(f"AgentManager failed to create agent: {e}")
381
+ # Fallback to direct file creation
382
+ file_path = await self._determine_agent_file_path(agent_name, tier)
383
+ path_ops.ensure_dir(file_path.parent)
384
+ path_ops.safe_write(file_path, agent_content)
385
+
386
+ # Track modification
387
+ modification = await self.modification_tracker.track_modification(
388
+ agent_name=agent_name,
389
+ modification_type=ModificationType.CREATE,
390
+ file_path=str(file_path),
391
+ tier=tier,
392
+ agent_type=agent_type,
393
+ **kwargs,
394
+ )
483
395
 
484
- if not persistence_record.success:
485
- result.error_message = persistence_record.error_message
486
- lifecycle_record.current_state = LifecycleState.CONFLICTED
487
-
488
- # Update performance metrics
489
- await self._update_performance_metrics(result)
396
+ # Note: We don't use persistence_service for the actual write anymore
397
+ # since AgentManager handles that. We create a synthetic record for compatibility.
398
+ persistence_record = PersistenceRecord(
399
+ operation_id=f"create_{agent_name}_{time.time()}",
400
+ operation_type=PersistenceOperation.CREATE,
401
+ agent_name=agent_name,
402
+ source_tier=tier,
403
+ target_tier=tier,
404
+ strategy=self.default_persistence_strategy,
405
+ success=True,
406
+ timestamp=time.time(),
407
+ file_path=str(file_path),
408
+ )
490
409
 
491
- self.operation_history.append(result)
492
- self.logger.info(
493
- f"Created agent '{agent_name}' in {result.duration_ms:.1f}ms"
494
- )
410
+ # Create lifecycle record
411
+ lifecycle_record = AgentLifecycleRecord(
412
+ agent_name=agent_name,
413
+ current_state=LifecycleState.ACTIVE,
414
+ tier=tier,
415
+ file_path=str(file_path),
416
+ created_at=time.time(),
417
+ last_modified=time.time(),
418
+ version="1.0.0",
419
+ modifications=[modification.modification_id],
420
+ persistence_operations=[persistence_record.operation_id],
421
+ metadata={"agent_type": agent_type, **kwargs},
422
+ )
495
423
 
496
- return result
424
+ self.agent_records[agent_name] = lifecycle_record
425
+
426
+ # Invalidate cache and update registry
427
+ cache_invalidated = await self._invalidate_agent_cache(agent_name)
428
+ registry_updated = await self._update_registry(agent_name)
429
+
430
+ # Create result
431
+ result = LifecycleOperationResult(
432
+ operation=LifecycleOperation.CREATE,
433
+ agent_name=agent_name,
434
+ success=persistence_record.success,
435
+ duration_ms=(time.time() - start_time) * 1000,
436
+ modification_id=modification.modification_id,
437
+ persistence_id=persistence_record.operation_id,
438
+ cache_invalidated=cache_invalidated,
439
+ registry_updated=registry_updated,
440
+ metadata={"file_path": str(file_path)},
441
+ )
497
442
 
498
- except Exception as e:
499
- result = LifecycleOperationResult(
500
- operation=LifecycleOperation.CREATE,
501
- agent_name=agent_name,
502
- success=False,
503
- duration_ms=(time.time() - start_time) * 1000,
504
- error_message=str(e),
505
- )
443
+ if not persistence_record.success:
444
+ result.error_message = persistence_record.error_message
445
+ lifecycle_record.current_state = LifecycleState.CONFLICTED
506
446
 
507
- self.operation_history.append(result)
508
- await self._update_performance_metrics(result)
447
+ # Update performance metrics
448
+ await self._update_performance_metrics(result)
509
449
 
510
- self.logger.error(f"Failed to create agent '{agent_name}': {e}")
511
- return result
450
+ self.operation_history.append(result)
451
+ self.logger.info(f"Created agent '{agent_name}' in {result.duration_ms:.1f}ms")
512
452
 
513
- finally:
514
- self.active_operations.pop(agent_name, None)
453
+ return result
515
454
 
516
455
  async def update_agent(
517
456
  self, agent_name: str, agent_content: str, **kwargs