claude-mpm 4.1.1__py3-none-any.whl → 4.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 (389) hide show
  1. claude_mpm/BUILD_NUMBER +1 -1
  2. claude_mpm/VERSION +1 -1
  3. claude_mpm/__main__.py +1 -1
  4. claude_mpm/agents/BASE_PM.md +74 -46
  5. claude_mpm/agents/INSTRUCTIONS.md +11 -153
  6. claude_mpm/agents/WORKFLOW.md +61 -321
  7. claude_mpm/agents/__init__.py +11 -11
  8. claude_mpm/agents/agent_loader.py +23 -20
  9. claude_mpm/agents/agent_loader_integration.py +1 -1
  10. claude_mpm/agents/agents_metadata.py +27 -0
  11. claude_mpm/agents/async_agent_loader.py +5 -8
  12. claude_mpm/agents/base_agent_loader.py +36 -25
  13. claude_mpm/agents/frontmatter_validator.py +6 -6
  14. claude_mpm/agents/schema/agent_schema.json +1 -1
  15. claude_mpm/agents/system_agent_config.py +9 -9
  16. claude_mpm/agents/templates/api_qa.json +47 -2
  17. claude_mpm/agents/templates/engineer.json +33 -11
  18. claude_mpm/agents/templates/imagemagick.json +256 -0
  19. claude_mpm/agents/templates/qa.json +41 -2
  20. claude_mpm/agents/templates/ticketing.json +5 -5
  21. claude_mpm/agents/templates/web_qa.json +50 -2
  22. claude_mpm/cli/__init__.py +51 -46
  23. claude_mpm/cli/__main__.py +1 -1
  24. claude_mpm/cli/commands/__init__.py +10 -12
  25. claude_mpm/cli/commands/agent_manager.py +186 -181
  26. claude_mpm/cli/commands/agents.py +648 -1098
  27. claude_mpm/cli/commands/aggregate.py +30 -29
  28. claude_mpm/cli/commands/cleanup.py +50 -44
  29. claude_mpm/cli/commands/cleanup_orphaned_agents.py +25 -25
  30. claude_mpm/cli/commands/config.py +162 -127
  31. claude_mpm/cli/commands/doctor.py +52 -62
  32. claude_mpm/cli/commands/info.py +37 -25
  33. claude_mpm/cli/commands/mcp.py +3 -7
  34. claude_mpm/cli/commands/mcp_command_router.py +14 -18
  35. claude_mpm/cli/commands/mcp_install_commands.py +28 -23
  36. claude_mpm/cli/commands/mcp_pipx_config.py +58 -49
  37. claude_mpm/cli/commands/mcp_server_commands.py +23 -17
  38. claude_mpm/cli/commands/memory.py +339 -967
  39. claude_mpm/cli/commands/monitor.py +117 -88
  40. claude_mpm/cli/commands/run.py +233 -542
  41. claude_mpm/cli/commands/socketio_monitor.py +17 -19
  42. claude_mpm/cli/commands/tickets.py +92 -92
  43. claude_mpm/cli/parser.py +1 -5
  44. claude_mpm/cli/parsers/__init__.py +1 -1
  45. claude_mpm/cli/parsers/agent_manager_parser.py +50 -98
  46. claude_mpm/cli/parsers/agents_parser.py +2 -3
  47. claude_mpm/cli/parsers/base_parser.py +7 -5
  48. claude_mpm/cli/parsers/mcp_parser.py +4 -2
  49. claude_mpm/cli/parsers/monitor_parser.py +26 -18
  50. claude_mpm/cli/shared/__init__.py +10 -10
  51. claude_mpm/cli/shared/argument_patterns.py +57 -71
  52. claude_mpm/cli/shared/base_command.py +61 -53
  53. claude_mpm/cli/shared/error_handling.py +62 -58
  54. claude_mpm/cli/shared/output_formatters.py +78 -77
  55. claude_mpm/cli/startup_logging.py +280 -172
  56. claude_mpm/cli/utils.py +10 -11
  57. claude_mpm/cli_module/__init__.py +1 -1
  58. claude_mpm/cli_module/args.py +1 -1
  59. claude_mpm/cli_module/migration_example.py +5 -5
  60. claude_mpm/config/__init__.py +9 -9
  61. claude_mpm/config/agent_config.py +15 -14
  62. claude_mpm/config/experimental_features.py +4 -4
  63. claude_mpm/config/paths.py +0 -1
  64. claude_mpm/config/socketio_config.py +5 -6
  65. claude_mpm/constants.py +1 -2
  66. claude_mpm/core/__init__.py +8 -8
  67. claude_mpm/core/agent_name_normalizer.py +1 -1
  68. claude_mpm/core/agent_registry.py +22 -29
  69. claude_mpm/core/agent_session_manager.py +3 -3
  70. claude_mpm/core/base_service.py +7 -15
  71. claude_mpm/core/cache.py +4 -6
  72. claude_mpm/core/claude_runner.py +85 -113
  73. claude_mpm/core/config.py +43 -28
  74. claude_mpm/core/config_aliases.py +0 -9
  75. claude_mpm/core/config_constants.py +52 -30
  76. claude_mpm/core/constants.py +0 -1
  77. claude_mpm/core/container.py +18 -27
  78. claude_mpm/core/exceptions.py +2 -2
  79. claude_mpm/core/factories.py +10 -12
  80. claude_mpm/core/framework_loader.py +500 -680
  81. claude_mpm/core/hook_manager.py +26 -22
  82. claude_mpm/core/hook_performance_config.py +58 -47
  83. claude_mpm/core/injectable_service.py +1 -1
  84. claude_mpm/core/interactive_session.py +61 -152
  85. claude_mpm/core/interfaces.py +1 -100
  86. claude_mpm/core/lazy.py +5 -5
  87. claude_mpm/core/log_manager.py +587 -0
  88. claude_mpm/core/logger.py +125 -8
  89. claude_mpm/core/logging_config.py +15 -17
  90. claude_mpm/core/minimal_framework_loader.py +5 -8
  91. claude_mpm/core/oneshot_session.py +15 -33
  92. claude_mpm/core/optimized_agent_loader.py +4 -6
  93. claude_mpm/core/optimized_startup.py +2 -1
  94. claude_mpm/core/output_style_manager.py +147 -106
  95. claude_mpm/core/pm_hook_interceptor.py +0 -1
  96. claude_mpm/core/service_registry.py +11 -8
  97. claude_mpm/core/session_manager.py +1 -2
  98. claude_mpm/core/shared/__init__.py +1 -1
  99. claude_mpm/core/shared/config_loader.py +101 -97
  100. claude_mpm/core/shared/path_resolver.py +72 -68
  101. claude_mpm/core/shared/singleton_manager.py +56 -50
  102. claude_mpm/core/socketio_pool.py +26 -6
  103. claude_mpm/core/tool_access_control.py +4 -5
  104. claude_mpm/core/typing_utils.py +50 -59
  105. claude_mpm/core/unified_agent_registry.py +14 -19
  106. claude_mpm/core/unified_config.py +4 -6
  107. claude_mpm/core/unified_paths.py +197 -109
  108. claude_mpm/dashboard/open_dashboard.py +2 -4
  109. claude_mpm/experimental/cli_enhancements.py +51 -36
  110. claude_mpm/generators/agent_profile_generator.py +2 -4
  111. claude_mpm/hooks/base_hook.py +1 -2
  112. claude_mpm/hooks/claude_hooks/connection_pool.py +72 -26
  113. claude_mpm/hooks/claude_hooks/event_handlers.py +99 -154
  114. claude_mpm/hooks/claude_hooks/hook_handler.py +110 -720
  115. claude_mpm/hooks/claude_hooks/hook_handler_eventbus.py +104 -77
  116. claude_mpm/hooks/claude_hooks/hook_handler_original.py +1040 -0
  117. claude_mpm/hooks/claude_hooks/hook_handler_refactored.py +347 -0
  118. claude_mpm/hooks/claude_hooks/memory_integration.py +2 -4
  119. claude_mpm/hooks/claude_hooks/response_tracking.py +15 -11
  120. claude_mpm/hooks/claude_hooks/services/__init__.py +13 -0
  121. claude_mpm/hooks/claude_hooks/services/connection_manager.py +190 -0
  122. claude_mpm/hooks/claude_hooks/services/duplicate_detector.py +106 -0
  123. claude_mpm/hooks/claude_hooks/services/state_manager.py +282 -0
  124. claude_mpm/hooks/claude_hooks/services/subagent_processor.py +374 -0
  125. claude_mpm/hooks/claude_hooks/tool_analysis.py +12 -18
  126. claude_mpm/hooks/memory_integration_hook.py +5 -5
  127. claude_mpm/hooks/tool_call_interceptor.py +1 -1
  128. claude_mpm/hooks/validation_hooks.py +4 -4
  129. claude_mpm/init.py +4 -9
  130. claude_mpm/models/__init__.py +2 -2
  131. claude_mpm/models/agent_session.py +11 -14
  132. claude_mpm/scripts/mcp_server.py +20 -11
  133. claude_mpm/scripts/mcp_wrapper.py +5 -5
  134. claude_mpm/scripts/mpm_doctor.py +321 -0
  135. claude_mpm/scripts/socketio_daemon.py +28 -25
  136. claude_mpm/scripts/socketio_daemon_hardened.py +298 -258
  137. claude_mpm/scripts/socketio_server_manager.py +116 -95
  138. claude_mpm/services/__init__.py +49 -49
  139. claude_mpm/services/agent_capabilities_service.py +12 -18
  140. claude_mpm/services/agents/__init__.py +22 -22
  141. claude_mpm/services/agents/agent_builder.py +140 -119
  142. claude_mpm/services/agents/deployment/__init__.py +3 -3
  143. claude_mpm/services/agents/deployment/agent_config_provider.py +9 -9
  144. claude_mpm/services/agents/deployment/agent_configuration_manager.py +19 -20
  145. claude_mpm/services/agents/deployment/agent_definition_factory.py +1 -5
  146. claude_mpm/services/agents/deployment/agent_deployment.py +129 -511
  147. claude_mpm/services/agents/deployment/agent_discovery_service.py +4 -8
  148. claude_mpm/services/agents/deployment/agent_environment_manager.py +2 -7
  149. claude_mpm/services/agents/deployment/agent_filesystem_manager.py +6 -10
  150. claude_mpm/services/agents/deployment/agent_format_converter.py +11 -15
  151. claude_mpm/services/agents/deployment/agent_frontmatter_validator.py +2 -3
  152. claude_mpm/services/agents/deployment/agent_lifecycle_manager.py +5 -5
  153. claude_mpm/services/agents/deployment/agent_metrics_collector.py +13 -19
  154. claude_mpm/services/agents/deployment/agent_restore_handler.py +0 -1
  155. claude_mpm/services/agents/deployment/agent_template_builder.py +26 -35
  156. claude_mpm/services/agents/deployment/agent_validator.py +0 -1
  157. claude_mpm/services/agents/deployment/agent_version_manager.py +7 -9
  158. claude_mpm/services/agents/deployment/agent_versioning.py +3 -3
  159. claude_mpm/services/agents/deployment/agents_directory_resolver.py +6 -7
  160. claude_mpm/services/agents/deployment/async_agent_deployment.py +51 -38
  161. claude_mpm/services/agents/deployment/base_agent_locator.py +132 -0
  162. claude_mpm/services/agents/deployment/config/__init__.py +1 -1
  163. claude_mpm/services/agents/deployment/config/deployment_config.py +7 -8
  164. claude_mpm/services/agents/deployment/deployment_results_manager.py +185 -0
  165. claude_mpm/services/agents/deployment/deployment_type_detector.py +1 -1
  166. claude_mpm/services/agents/deployment/deployment_wrapper.py +18 -18
  167. claude_mpm/services/agents/deployment/facade/__init__.py +1 -1
  168. claude_mpm/services/agents/deployment/facade/deployment_executor.py +0 -3
  169. claude_mpm/services/agents/deployment/facade/deployment_facade.py +3 -4
  170. claude_mpm/services/agents/deployment/interface_adapter.py +5 -7
  171. claude_mpm/services/agents/deployment/multi_source_deployment_service.py +345 -276
  172. claude_mpm/services/agents/deployment/pipeline/__init__.py +2 -2
  173. claude_mpm/services/agents/deployment/pipeline/pipeline_builder.py +1 -1
  174. claude_mpm/services/agents/deployment/pipeline/pipeline_context.py +6 -4
  175. claude_mpm/services/agents/deployment/pipeline/pipeline_executor.py +3 -3
  176. claude_mpm/services/agents/deployment/pipeline/steps/__init__.py +2 -2
  177. claude_mpm/services/agents/deployment/pipeline/steps/agent_processing_step.py +14 -13
  178. claude_mpm/services/agents/deployment/pipeline/steps/base_step.py +0 -1
  179. claude_mpm/services/agents/deployment/pipeline/steps/configuration_step.py +1 -1
  180. claude_mpm/services/agents/deployment/pipeline/steps/target_directory_step.py +8 -9
  181. claude_mpm/services/agents/deployment/pipeline/steps/validation_step.py +1 -1
  182. claude_mpm/services/agents/deployment/processors/__init__.py +1 -1
  183. claude_mpm/services/agents/deployment/processors/agent_processor.py +20 -16
  184. claude_mpm/services/agents/deployment/refactored_agent_deployment_service.py +5 -12
  185. claude_mpm/services/agents/deployment/results/__init__.py +1 -1
  186. claude_mpm/services/agents/deployment/results/deployment_result_builder.py +1 -1
  187. claude_mpm/services/agents/deployment/single_agent_deployer.py +315 -0
  188. claude_mpm/services/agents/deployment/strategies/__init__.py +2 -2
  189. claude_mpm/services/agents/deployment/strategies/base_strategy.py +1 -7
  190. claude_mpm/services/agents/deployment/strategies/project_strategy.py +1 -4
  191. claude_mpm/services/agents/deployment/strategies/system_strategy.py +2 -3
  192. claude_mpm/services/agents/deployment/strategies/user_strategy.py +3 -7
  193. claude_mpm/services/agents/deployment/validation/__init__.py +1 -1
  194. claude_mpm/services/agents/deployment/validation/agent_validator.py +1 -1
  195. claude_mpm/services/agents/deployment/validation/template_validator.py +2 -2
  196. claude_mpm/services/agents/deployment/validation/validation_result.py +2 -6
  197. claude_mpm/services/agents/loading/__init__.py +1 -1
  198. claude_mpm/services/agents/loading/agent_profile_loader.py +6 -12
  199. claude_mpm/services/agents/loading/base_agent_manager.py +5 -5
  200. claude_mpm/services/agents/loading/framework_agent_loader.py +2 -4
  201. claude_mpm/services/agents/management/__init__.py +1 -1
  202. claude_mpm/services/agents/management/agent_capabilities_generator.py +1 -3
  203. claude_mpm/services/agents/management/agent_management_service.py +5 -9
  204. claude_mpm/services/agents/memory/__init__.py +4 -4
  205. claude_mpm/services/agents/memory/agent_memory_manager.py +157 -503
  206. claude_mpm/services/agents/memory/agent_persistence_service.py +0 -2
  207. claude_mpm/services/agents/memory/content_manager.py +44 -38
  208. claude_mpm/services/agents/memory/memory_categorization_service.py +165 -0
  209. claude_mpm/services/agents/memory/memory_file_service.py +103 -0
  210. claude_mpm/services/agents/memory/memory_format_service.py +201 -0
  211. claude_mpm/services/agents/memory/memory_limits_service.py +99 -0
  212. claude_mpm/services/agents/memory/template_generator.py +4 -6
  213. claude_mpm/services/agents/registry/__init__.py +11 -7
  214. claude_mpm/services/agents/registry/deployed_agent_discovery.py +30 -27
  215. claude_mpm/services/agents/registry/modification_tracker.py +3 -6
  216. claude_mpm/services/async_session_logger.py +1 -2
  217. claude_mpm/services/claude_session_logger.py +1 -2
  218. claude_mpm/services/cli/__init__.py +18 -0
  219. claude_mpm/services/cli/agent_cleanup_service.py +407 -0
  220. claude_mpm/services/cli/agent_dependency_service.py +395 -0
  221. claude_mpm/services/cli/agent_listing_service.py +463 -0
  222. claude_mpm/services/cli/agent_output_formatter.py +605 -0
  223. claude_mpm/services/cli/agent_validation_service.py +589 -0
  224. claude_mpm/services/cli/dashboard_launcher.py +424 -0
  225. claude_mpm/services/cli/memory_crud_service.py +617 -0
  226. claude_mpm/services/cli/memory_output_formatter.py +604 -0
  227. claude_mpm/services/cli/session_manager.py +513 -0
  228. claude_mpm/services/cli/socketio_manager.py +498 -0
  229. claude_mpm/services/cli/startup_checker.py +370 -0
  230. claude_mpm/services/command_deployment_service.py +173 -0
  231. claude_mpm/services/command_handler_service.py +20 -22
  232. claude_mpm/services/core/__init__.py +25 -25
  233. claude_mpm/services/core/base.py +0 -5
  234. claude_mpm/services/core/cache_manager.py +311 -0
  235. claude_mpm/services/core/interfaces/__init__.py +32 -32
  236. claude_mpm/services/core/interfaces/agent.py +0 -21
  237. claude_mpm/services/core/interfaces/communication.py +0 -27
  238. claude_mpm/services/core/interfaces/infrastructure.py +0 -56
  239. claude_mpm/services/core/interfaces/service.py +0 -29
  240. claude_mpm/services/core/memory_manager.py +637 -0
  241. claude_mpm/services/core/path_resolver.py +498 -0
  242. claude_mpm/services/core/service_container.py +520 -0
  243. claude_mpm/services/core/service_interfaces.py +436 -0
  244. claude_mpm/services/diagnostics/__init__.py +1 -1
  245. claude_mpm/services/diagnostics/checks/__init__.py +6 -6
  246. claude_mpm/services/diagnostics/checks/agent_check.py +152 -97
  247. claude_mpm/services/diagnostics/checks/base_check.py +12 -16
  248. claude_mpm/services/diagnostics/checks/claude_desktop_check.py +84 -81
  249. claude_mpm/services/diagnostics/checks/common_issues_check.py +99 -91
  250. claude_mpm/services/diagnostics/checks/configuration_check.py +82 -77
  251. claude_mpm/services/diagnostics/checks/filesystem_check.py +67 -68
  252. claude_mpm/services/diagnostics/checks/installation_check.py +254 -94
  253. claude_mpm/services/diagnostics/checks/mcp_check.py +90 -88
  254. claude_mpm/services/diagnostics/checks/monitor_check.py +75 -76
  255. claude_mpm/services/diagnostics/checks/startup_log_check.py +67 -73
  256. claude_mpm/services/diagnostics/diagnostic_runner.py +67 -59
  257. claude_mpm/services/diagnostics/doctor_reporter.py +107 -70
  258. claude_mpm/services/diagnostics/models.py +21 -19
  259. claude_mpm/services/event_aggregator.py +10 -17
  260. claude_mpm/services/event_bus/__init__.py +1 -1
  261. claude_mpm/services/event_bus/config.py +54 -35
  262. claude_mpm/services/event_bus/event_bus.py +76 -71
  263. claude_mpm/services/event_bus/relay.py +74 -64
  264. claude_mpm/services/events/__init__.py +11 -11
  265. claude_mpm/services/events/consumers/__init__.py +3 -3
  266. claude_mpm/services/events/consumers/dead_letter.py +71 -63
  267. claude_mpm/services/events/consumers/logging.py +39 -37
  268. claude_mpm/services/events/consumers/metrics.py +56 -57
  269. claude_mpm/services/events/consumers/socketio.py +82 -81
  270. claude_mpm/services/events/core.py +110 -99
  271. claude_mpm/services/events/interfaces.py +56 -72
  272. claude_mpm/services/events/producers/__init__.py +1 -1
  273. claude_mpm/services/events/producers/hook.py +38 -38
  274. claude_mpm/services/events/producers/system.py +46 -44
  275. claude_mpm/services/exceptions.py +81 -80
  276. claude_mpm/services/framework_claude_md_generator/__init__.py +2 -4
  277. claude_mpm/services/framework_claude_md_generator/content_assembler.py +3 -5
  278. claude_mpm/services/framework_claude_md_generator/content_validator.py +1 -1
  279. claude_mpm/services/framework_claude_md_generator/deployment_manager.py +4 -4
  280. claude_mpm/services/framework_claude_md_generator/section_generators/__init__.py +0 -1
  281. claude_mpm/services/framework_claude_md_generator/section_generators/agents.py +0 -2
  282. claude_mpm/services/framework_claude_md_generator/version_manager.py +4 -5
  283. claude_mpm/services/hook_service.py +6 -9
  284. claude_mpm/services/infrastructure/__init__.py +1 -1
  285. claude_mpm/services/infrastructure/context_preservation.py +8 -12
  286. claude_mpm/services/infrastructure/monitoring.py +21 -23
  287. claude_mpm/services/mcp_gateway/__init__.py +37 -37
  288. claude_mpm/services/mcp_gateway/auto_configure.py +95 -103
  289. claude_mpm/services/mcp_gateway/config/__init__.py +1 -1
  290. claude_mpm/services/mcp_gateway/config/config_loader.py +23 -25
  291. claude_mpm/services/mcp_gateway/config/config_schema.py +5 -5
  292. claude_mpm/services/mcp_gateway/config/configuration.py +9 -6
  293. claude_mpm/services/mcp_gateway/core/__init__.py +10 -10
  294. claude_mpm/services/mcp_gateway/core/base.py +0 -3
  295. claude_mpm/services/mcp_gateway/core/interfaces.py +1 -38
  296. claude_mpm/services/mcp_gateway/core/process_pool.py +99 -93
  297. claude_mpm/services/mcp_gateway/core/singleton_manager.py +65 -62
  298. claude_mpm/services/mcp_gateway/core/startup_verification.py +75 -74
  299. claude_mpm/services/mcp_gateway/main.py +2 -1
  300. claude_mpm/services/mcp_gateway/registry/service_registry.py +5 -8
  301. claude_mpm/services/mcp_gateway/registry/tool_registry.py +1 -1
  302. claude_mpm/services/mcp_gateway/server/__init__.py +1 -1
  303. claude_mpm/services/mcp_gateway/server/mcp_gateway.py +12 -19
  304. claude_mpm/services/mcp_gateway/server/stdio_handler.py +4 -3
  305. claude_mpm/services/mcp_gateway/server/stdio_server.py +79 -71
  306. claude_mpm/services/mcp_gateway/tools/__init__.py +2 -2
  307. claude_mpm/services/mcp_gateway/tools/base_adapter.py +5 -6
  308. claude_mpm/services/mcp_gateway/tools/document_summarizer.py +13 -22
  309. claude_mpm/services/mcp_gateway/tools/health_check_tool.py +79 -78
  310. claude_mpm/services/mcp_gateway/tools/hello_world.py +12 -14
  311. claude_mpm/services/mcp_gateway/tools/ticket_tools.py +42 -49
  312. claude_mpm/services/mcp_gateway/tools/unified_ticket_tool.py +51 -55
  313. claude_mpm/services/memory/__init__.py +3 -3
  314. claude_mpm/services/memory/builder.py +3 -6
  315. claude_mpm/services/memory/cache/__init__.py +1 -1
  316. claude_mpm/services/memory/cache/shared_prompt_cache.py +3 -5
  317. claude_mpm/services/memory/cache/simple_cache.py +1 -1
  318. claude_mpm/services/memory/indexed_memory.py +5 -7
  319. claude_mpm/services/memory/optimizer.py +7 -10
  320. claude_mpm/services/memory/router.py +8 -9
  321. claude_mpm/services/memory_hook_service.py +48 -34
  322. claude_mpm/services/monitor_build_service.py +77 -73
  323. claude_mpm/services/port_manager.py +130 -108
  324. claude_mpm/services/project/analyzer.py +12 -10
  325. claude_mpm/services/project/registry.py +11 -11
  326. claude_mpm/services/recovery_manager.py +10 -19
  327. claude_mpm/services/response_tracker.py +0 -1
  328. claude_mpm/services/runner_configuration_service.py +19 -20
  329. claude_mpm/services/session_management_service.py +7 -11
  330. claude_mpm/services/shared/__init__.py +1 -1
  331. claude_mpm/services/shared/async_service_base.py +58 -50
  332. claude_mpm/services/shared/config_service_base.py +73 -67
  333. claude_mpm/services/shared/lifecycle_service_base.py +82 -78
  334. claude_mpm/services/shared/manager_base.py +94 -82
  335. claude_mpm/services/shared/service_factory.py +96 -98
  336. claude_mpm/services/socketio/__init__.py +3 -3
  337. claude_mpm/services/socketio/client_proxy.py +5 -5
  338. claude_mpm/services/socketio/event_normalizer.py +199 -181
  339. claude_mpm/services/socketio/handlers/__init__.py +3 -3
  340. claude_mpm/services/socketio/handlers/base.py +5 -4
  341. claude_mpm/services/socketio/handlers/connection.py +163 -136
  342. claude_mpm/services/socketio/handlers/file.py +13 -14
  343. claude_mpm/services/socketio/handlers/git.py +12 -7
  344. claude_mpm/services/socketio/handlers/hook.py +49 -44
  345. claude_mpm/services/socketio/handlers/memory.py +0 -1
  346. claude_mpm/services/socketio/handlers/project.py +0 -1
  347. claude_mpm/services/socketio/handlers/registry.py +37 -19
  348. claude_mpm/services/socketio/migration_utils.py +98 -84
  349. claude_mpm/services/socketio/server/__init__.py +1 -1
  350. claude_mpm/services/socketio/server/broadcaster.py +81 -87
  351. claude_mpm/services/socketio/server/core.py +65 -54
  352. claude_mpm/services/socketio/server/eventbus_integration.py +95 -56
  353. claude_mpm/services/socketio/server/main.py +64 -38
  354. claude_mpm/services/socketio_client_manager.py +10 -12
  355. claude_mpm/services/subprocess_launcher_service.py +4 -7
  356. claude_mpm/services/system_instructions_service.py +13 -14
  357. claude_mpm/services/ticket_manager.py +2 -2
  358. claude_mpm/services/utility_service.py +5 -13
  359. claude_mpm/services/version_control/__init__.py +16 -16
  360. claude_mpm/services/version_control/branch_strategy.py +5 -8
  361. claude_mpm/services/version_control/conflict_resolution.py +9 -23
  362. claude_mpm/services/version_control/git_operations.py +5 -7
  363. claude_mpm/services/version_control/semantic_versioning.py +16 -17
  364. claude_mpm/services/version_control/version_parser.py +13 -18
  365. claude_mpm/services/version_service.py +10 -11
  366. claude_mpm/storage/__init__.py +1 -1
  367. claude_mpm/storage/state_storage.py +22 -28
  368. claude_mpm/utils/__init__.py +6 -6
  369. claude_mpm/utils/agent_dependency_loader.py +47 -33
  370. claude_mpm/utils/config_manager.py +11 -14
  371. claude_mpm/utils/dependency_cache.py +1 -1
  372. claude_mpm/utils/dependency_manager.py +13 -17
  373. claude_mpm/utils/dependency_strategies.py +8 -10
  374. claude_mpm/utils/environment_context.py +3 -9
  375. claude_mpm/utils/error_handler.py +3 -13
  376. claude_mpm/utils/file_utils.py +1 -1
  377. claude_mpm/utils/path_operations.py +8 -12
  378. claude_mpm/utils/robust_installer.py +110 -33
  379. claude_mpm/utils/subprocess_utils.py +5 -6
  380. claude_mpm/validation/agent_validator.py +3 -6
  381. claude_mpm/validation/frontmatter_validator.py +1 -1
  382. {claude_mpm-4.1.1.dist-info → claude_mpm-4.1.3.dist-info}/METADATA +1 -1
  383. claude_mpm-4.1.3.dist-info/RECORD +528 -0
  384. claude_mpm/cli/commands/run_config_checker.py +0 -160
  385. claude_mpm-4.1.1.dist-info/RECORD +0 -494
  386. {claude_mpm-4.1.1.dist-info → claude_mpm-4.1.3.dist-info}/WHEEL +0 -0
  387. {claude_mpm-4.1.1.dist-info → claude_mpm-4.1.3.dist-info}/entry_points.txt +0 -0
  388. {claude_mpm-4.1.1.dist-info → claude_mpm-4.1.3.dist-info}/licenses/LICENSE +0 -0
  389. {claude_mpm-4.1.1.dist-info → claude_mpm-4.1.3.dist-info}/top_level.txt +0 -0
@@ -26,7 +26,7 @@ import logging
26
26
  import os
27
27
  from enum import Enum
28
28
  from pathlib import Path
29
- from typing import Any, Dict, Optional
29
+ from typing import Dict, Optional
30
30
 
31
31
  from claude_mpm.services.memory.cache.shared_prompt_cache import SharedPromptCache
32
32
 
@@ -39,7 +39,7 @@ BASE_AGENT_CACHE_KEY = "base_agent:instructions"
39
39
 
40
40
  def _get_base_agent_file() -> Path:
41
41
  """Get the base agent file path with priority-based search.
42
-
42
+
43
43
  Priority order:
44
44
  1. Environment variable override (CLAUDE_MPM_BASE_AGENT_PATH)
45
45
  2. Current working directory (for local development)
@@ -54,53 +54,66 @@ def _get_base_agent_file() -> Path:
54
54
  if env_base_agent.exists():
55
55
  logger.info(f"Using environment variable base_agent: {env_base_agent}")
56
56
  return env_base_agent
57
- else:
58
- logger.warning(f"CLAUDE_MPM_BASE_AGENT_PATH set but file doesn't exist: {env_base_agent}")
59
-
57
+ logger.warning(
58
+ f"CLAUDE_MPM_BASE_AGENT_PATH set but file doesn't exist: {env_base_agent}"
59
+ )
60
+
60
61
  # Priority 1: Check current working directory for local development
61
62
  cwd = Path.cwd()
62
63
  cwd_base_agent = cwd / "src" / "claude_mpm" / "agents" / "base_agent.json"
63
64
  if cwd_base_agent.exists():
64
65
  logger.info(f"Using local development base_agent from cwd: {cwd_base_agent}")
65
66
  return cwd_base_agent
66
-
67
+
67
68
  # Priority 2: Check known development locations
68
69
  known_dev_paths = [
69
70
  Path("/Users/masa/Projects/claude-mpm/src/claude_mpm/agents/base_agent.json"),
70
- Path.home() / "Projects" / "claude-mpm" / "src" / "claude_mpm" / "agents" / "base_agent.json",
71
- Path.home() / "projects" / "claude-mpm" / "src" / "claude_mpm" / "agents" / "base_agent.json",
71
+ Path.home()
72
+ / "Projects"
73
+ / "claude-mpm"
74
+ / "src"
75
+ / "claude_mpm"
76
+ / "agents"
77
+ / "base_agent.json",
78
+ Path.home()
79
+ / "projects"
80
+ / "claude-mpm"
81
+ / "src"
82
+ / "claude_mpm"
83
+ / "agents"
84
+ / "base_agent.json",
72
85
  ]
73
-
86
+
74
87
  for dev_path in known_dev_paths:
75
88
  if dev_path.exists():
76
89
  logger.info(f"Using development base_agent: {dev_path}")
77
90
  return dev_path
78
-
91
+
79
92
  # Priority 3: Check user override location
80
93
  user_base_agent = Path.home() / ".claude" / "agents" / "base_agent.json"
81
94
  if user_base_agent.exists():
82
95
  logger.info(f"Using user override base_agent: {user_base_agent}")
83
96
  return user_base_agent
84
-
97
+
85
98
  # Priority 4: Check if we're running from a wheel installation
86
99
  try:
87
100
  import claude_mpm
88
101
 
89
102
  package_path = Path(claude_mpm.__file__).parent
90
103
  path_str = str(package_path.resolve())
91
-
104
+
92
105
  # For development/editable installs, check if there's a local src directory
93
106
  if "site-packages" in path_str or "dist-packages" in path_str:
94
107
  # Check if this is a pipx/pip installation
95
108
  if "pipx" in path_str:
96
109
  logger.debug(f"Detected pipx installation at {package_path}")
97
-
110
+
98
111
  # For wheel installations, check data directory
99
112
  data_base_agent = package_path / "data" / "agents" / "base_agent.json"
100
113
  if data_base_agent.exists():
101
114
  logger.info(f"Using wheel installation base_agent: {data_base_agent}")
102
115
  return data_base_agent
103
-
116
+
104
117
  # Also check direct agents directory in package
105
118
  pkg_base_agent = package_path / "agents" / "base_agent.json"
106
119
  if pkg_base_agent.exists():
@@ -108,7 +121,7 @@ def _get_base_agent_file() -> Path:
108
121
  return pkg_base_agent
109
122
  except Exception as e:
110
123
  logger.debug(f"Exception checking package path: {e}")
111
-
124
+
112
125
  # Final fallback: Use the base_agent.json relative to this file
113
126
  base_agent_path = Path(__file__).parent / "base_agent.json"
114
127
  if base_agent_path.exists():
@@ -117,7 +130,7 @@ def _get_base_agent_file() -> Path:
117
130
 
118
131
  # Error if no base agent found
119
132
  logger.error("Base agent template file not found in any location")
120
- logger.error(f"Searched locations:")
133
+ logger.error("Searched locations:")
121
134
  logger.error(f" 1. CWD: {cwd_base_agent}")
122
135
  logger.error(f" 2. Dev paths: {known_dev_paths}")
123
136
  logger.error(f" 3. User: {user_base_agent}")
@@ -244,7 +257,7 @@ def load_base_agent_instructions(force_reload: bool = False) -> Optional[str]:
244
257
  logger.debug(f"Loading base agent instructions from: {base_agent_file}")
245
258
 
246
259
  # Load JSON and extract instructions
247
- with open(base_agent_file, "r", encoding="utf-8") as f:
260
+ with open(base_agent_file, encoding="utf-8") as f:
248
261
  base_agent_data = json.load(f)
249
262
 
250
263
  # Extract instructions from the JSON structure
@@ -366,7 +379,7 @@ def _build_dynamic_prompt(content: str, template: PromptTemplate) -> str:
366
379
 
367
380
  # Add sections based on template
368
381
  template_name = template.value
369
- for section_key, section_config in TEMPLATE_SECTIONS.items():
382
+ for _section_key, section_config in TEMPLATE_SECTIONS.items():
370
383
  if template_name in section_config["templates"]:
371
384
  section_name = section_config["content"]
372
385
  assert isinstance(section_name, str), "Section name must be string"
@@ -543,9 +556,7 @@ def prepend_base_instructions(
543
556
  )
544
557
 
545
558
  # Combine base instructions with agent prompt
546
- combined_prompt = f"{base_instructions}{separator}{agent_prompt}"
547
-
548
- return combined_prompt
559
+ return f"{base_instructions}{separator}{agent_prompt}"
549
560
 
550
561
 
551
562
  def clear_base_agent_cache() -> None:
@@ -603,11 +614,11 @@ if not validate_base_agent_file():
603
614
 
604
615
  # Export key components
605
616
  __all__ = [
606
- "prepend_base_instructions",
607
- "load_base_agent_instructions",
617
+ "TEMPLATE_SECTIONS",
618
+ "PromptTemplate",
608
619
  "clear_base_agent_cache",
609
620
  "get_base_agent_path",
621
+ "load_base_agent_instructions",
622
+ "prepend_base_instructions",
610
623
  "validate_base_agent_file",
611
- "PromptTemplate",
612
- "TEMPLATE_SECTIONS",
613
624
  ]
@@ -36,9 +36,9 @@ class ValidationResult:
36
36
  warnings: List[str]
37
37
  corrections: List[str]
38
38
  corrected_frontmatter: Optional[Dict[str, Any]] = None
39
- field_corrections: Optional[
40
- Dict[str, Any]
41
- ] = None # Specific field-level corrections
39
+ field_corrections: Optional[Dict[str, Any]] = (
40
+ None # Specific field-level corrections
41
+ )
42
42
 
43
43
 
44
44
  class FrontmatterValidator:
@@ -139,7 +139,7 @@ class FrontmatterValidator:
139
139
  )
140
140
  if schema_path.exists():
141
141
  try:
142
- with open(schema_path, "r") as f:
142
+ with open(schema_path) as f:
143
143
  return json.load(f)
144
144
  except Exception as e:
145
145
  logger.warning(f"Failed to load frontmatter schema: {e}")
@@ -510,7 +510,7 @@ class FrontmatterValidator:
510
510
  ValidationResult with validation status
511
511
  """
512
512
  try:
513
- with open(file_path, "r") as f:
513
+ with open(file_path) as f:
514
514
  content = f.read()
515
515
 
516
516
  # Extract frontmatter
@@ -574,7 +574,7 @@ class FrontmatterValidator:
574
574
 
575
575
  if result.field_corrections and not dry_run:
576
576
  try:
577
- with open(file_path, "r") as f:
577
+ with open(file_path) as f:
578
578
  content = f.read()
579
579
 
580
580
  # Find frontmatter boundaries
@@ -24,7 +24,7 @@
24
24
  "agent_type": {
25
25
  "type": "string",
26
26
  "description": "Type of agent",
27
- "enum": ["base", "engineer", "qa", "documentation", "research", "security", "ops", "data_engineer", "version_control", "project_organizer"]
27
+ "enum": ["base", "engineer", "qa", "documentation", "research", "security", "ops", "data_engineer", "version_control", "project_organizer", "imagemagick"]
28
28
  },
29
29
  "metadata": {
30
30
  "type": "object",
@@ -17,7 +17,7 @@ Created: 2025-07-16
17
17
 
18
18
  import logging
19
19
  from dataclasses import dataclass, field
20
- from typing import Any, Dict, List, Optional, Type
20
+ from typing import Any, Dict, List, Optional
21
21
 
22
22
  from ..config.default_model_config import (
23
23
  DefaultModelConfigManager,
@@ -27,7 +27,7 @@ from ..config.model_env_defaults import (
27
27
  ModelEnvironmentLoader,
28
28
  get_model_for_agent_from_env,
29
29
  )
30
- from ..services.model_selector import ModelSelectionCriteria, ModelSelector, ModelType
30
+ from ..services.model_selector import ModelSelector, ModelType
31
31
 
32
32
  logger = logging.getLogger(__name__)
33
33
 
@@ -518,8 +518,8 @@ class SystemAgentConfigManager:
518
518
  "capabilities_coverage": {
519
519
  "total_capabilities": len(all_capabilities),
520
520
  "total_specializations": len(all_specializations),
521
- "unique_capabilities": sorted(list(all_capabilities)),
522
- "unique_specializations": sorted(list(all_specializations)),
521
+ "unique_capabilities": sorted(all_capabilities),
522
+ "unique_specializations": sorted(all_specializations),
523
523
  },
524
524
  "configuration_health": self.validate_agent_model_assignments(),
525
525
  }
@@ -620,13 +620,13 @@ if __name__ == "__main__":
620
620
 
621
621
  # Show model distribution
622
622
  distribution = manager.get_model_distribution()
623
- print(f"\nModel Distribution:")
623
+ print("\nModel Distribution:")
624
624
  for model_id, count in distribution.items():
625
625
  print(f" {model_id}: {count} agents")
626
626
 
627
627
  # Show agents by model
628
- print(f"\nAgents by Model:")
629
- for model_id in distribution.keys():
628
+ print("\nAgents by Model:")
629
+ for model_id in distribution:
630
630
  agents_with_model = manager.get_agents_by_model(model_id)
631
631
  print(f" {model_id}:")
632
632
  for agent in agents_with_model:
@@ -634,7 +634,7 @@ if __name__ == "__main__":
634
634
 
635
635
  # Validation
636
636
  validation = manager.validate_agent_model_assignments()
637
- print(f"\nValidation Results:")
637
+ print("\nValidation Results:")
638
638
  print(f" Valid: {validation['valid']}")
639
639
  print(f" Issues: {len(validation['issues'])}")
640
640
  print(f" Warnings: {len(validation['warnings'])}")
@@ -642,7 +642,7 @@ if __name__ == "__main__":
642
642
 
643
643
  # Configuration summary
644
644
  summary = manager.get_configuration_summary()
645
- print(f"\nConfiguration Summary:")
645
+ print("\nConfiguration Summary:")
646
646
  print(f" Enabled Agents: {summary['enabled_agents']}")
647
647
  print(f" Environment Overrides: {len(summary['environment_overrides'])}")
648
648
  print(
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "schema_version": "1.2.0",
3
3
  "agent_id": "api-qa-agent",
4
- "agent_version": "1.0.0",
4
+ "agent_version": "1.1.0",
5
5
  "agent_type": "qa",
6
6
  "metadata": {
7
7
  "name": "API QA Agent",
@@ -20,9 +20,54 @@
20
20
  ],
21
21
  "author": "Claude MPM Team",
22
22
  "created_at": "2025-08-19T00:00:00.000000Z",
23
- "updated_at": "2025-08-19T00:00:00.000000Z",
23
+ "updated_at": "2025-08-24T00:00:00.000000Z",
24
24
  "color": "blue"
25
25
  },
26
+ "routing": {
27
+ "keywords": [
28
+ "api",
29
+ "endpoint",
30
+ "rest",
31
+ "graphql",
32
+ "backend",
33
+ "server",
34
+ "auth",
35
+ "authentication",
36
+ "authorization",
37
+ "database",
38
+ "microservice",
39
+ "webhook",
40
+ "oauth",
41
+ "jwt",
42
+ "token"
43
+ ],
44
+ "paths": [
45
+ "/api/",
46
+ "/routes/",
47
+ "/controllers/",
48
+ "/services/",
49
+ "/models/",
50
+ "/middleware/",
51
+ "/handlers/",
52
+ "/resolvers/",
53
+ "/schemas/"
54
+ ],
55
+ "extensions": [
56
+ ".py",
57
+ ".js",
58
+ ".ts",
59
+ ".go",
60
+ ".java",
61
+ ".rb",
62
+ ".php",
63
+ ".cs",
64
+ ".graphql",
65
+ ".gql"
66
+ ],
67
+ "priority": 100,
68
+ "confidence_threshold": 0.7,
69
+ "description": "Use for backend API, REST, GraphQL, and server-side testing"
70
+ },
26
71
  "capabilities": {
27
72
  "model": "sonnet",
28
73
  "tools": [
@@ -1,11 +1,21 @@
1
1
  {
2
2
  "name": "Engineer Agent",
3
- "description": "Clean architecture specialist with SOLID principles, aggressive code reuse, and systematic code reduction",
3
+ "description": "Clean architecture specialist with AGGRESSIVE code reduction focus, strict modularization, and dependency injection",
4
4
  "schema_version": "1.2.0",
5
5
  "agent_id": "engineer",
6
- "agent_version": "3.5.1",
7
- "template_version": "1.0.1",
6
+ "agent_version": "3.7.0",
7
+ "template_version": "2.0.0",
8
8
  "template_changelog": [
9
+ {
10
+ "version": "2.0.0",
11
+ "date": "2025-08-24",
12
+ "description": "Major Enhancement: CODE REDUCTION IMPERATIVE as #1 priority, 800-line hard limit (up from 500), dependency injection as DEFAULT pattern, enhanced refactoring triggers"
13
+ },
14
+ {
15
+ "version": "1.1.0",
16
+ "date": "2025-08-24",
17
+ "description": "Enhanced: Added aggressive code reduction imperative, 800-line file limit, and dependency injection requirements"
18
+ },
9
19
  {
10
20
  "version": "1.0.1",
11
21
  "date": "2025-08-22",
@@ -20,7 +30,7 @@
20
30
  "agent_type": "engineer",
21
31
  "metadata": {
22
32
  "name": "Engineer Agent",
23
- "description": "Clean architecture specialist with SOLID principles, aggressive code reuse, and systematic code reduction",
33
+ "description": "Clean architecture specialist with AGGRESSIVE code reduction focus, strict modularization, and dependency injection",
24
34
  "category": "engineering",
25
35
  "tags": [
26
36
  "engineering",
@@ -31,11 +41,14 @@
31
41
  "refactoring",
32
42
  "code-reuse",
33
43
  "pattern-adherence",
34
- "integration"
44
+ "integration",
45
+ "dependency-injection",
46
+ "modularization",
47
+ "800-line-limit"
35
48
  ],
36
49
  "author": "Claude MPM Team",
37
50
  "created_at": "2025-07-27T03:45:51.472561Z",
38
- "updated_at": "2025-08-22T12:00:00.000000Z",
51
+ "updated_at": "2025-08-24T15:30:00.000000Z",
39
52
  "color": "blue"
40
53
  },
41
54
  "capabilities": {
@@ -68,31 +81,40 @@
68
81
  ]
69
82
  }
70
83
  },
71
- "instructions": "# Engineer Agent\n\n**Inherits from**: BASE_AGENT_TEMPLATE.md\n**Focus**: Clean architecture and code reduction specialist\n\n## Core Expertise\n\nImplement solutions with relentless focus on SOLID principles, aggressive code reuse, and systematic complexity reduction.\n\n## Engineering Standards\n\n### SOLID Principles (MANDATORY)\n- **S**: Single Responsibility - Each unit does ONE thing well\n- **O**: Open/Closed - Extend without modification\n- **L**: Liskov Substitution - Derived classes fully substitutable\n- **I**: Interface Segregation - Many specific interfaces\n- **D**: Dependency Inversion - Depend on abstractions\n\n### Code Organization Rules\n- **File Length**: Maximum 500 lines (refactor at 400)\n- **Function Length**: Maximum 50 lines (ideal: 20-30)\n- **Nesting Depth**: Maximum 3 levels\n- **Module Structure**: Split by feature/domain when approaching limits\n- **Parameters**: Maximum 5 per function (use objects for more)\n\n### Before Writing Code Checklist\n1. \u2713 Search for existing similar functionality (Grep/Glob)\n2. \u2713 Can refactoring existing code solve this?\n3. \u2713 Is new code absolutely necessary?\n\n## Implementation Checklist\n\n**Pre-Implementation**:\n- [ ] Review agent memory for patterns and learnings\n- [ ] Validate research findings are current\n- [ ] Confirm codebase patterns and constraints\n- [ ] Check for existing similar functionality\n- [ ] Plan module structure if file will exceed 400 lines\n\n**During Implementation**:\n- [ ] Apply SOLID principles\n- [ ] Keep functions under 50 lines\n- [ ] Maximum 3 levels of nesting\n- [ ] Extract shared logic immediately (DRY)\n- [ ] Separate business logic from infrastructure\n- [ ] Document WHY, not just what\n\n**Post-Implementation**:\n- [ ] Files under 500 lines?\n- [ ] Functions single-purpose?\n- [ ] Could reuse more existing code?\n- [ ] Is this the simplest solution?\n- [ ] Tests cover happy path and edge cases?\n\n## Implementation Chunking Strategy\n\nFor large implementations:\n1. Identify module boundaries with Grep\n2. Read first 100 lines \u2192 Implement \u2192 Discard\n3. Read next chunk \u2192 Implement with context \u2192 Discard\n4. Use module interfaces as implementation guides\n5. Cache ONLY: interfaces, types, and function signatures\n\n## Testing Requirements\n\n- Unit tests for all public functions\n- Test happy path AND edge cases\n- Co-locate tests with code\n- Mock external dependencies\n- Ensure isolation and repeatability\n\n## Documentation Standards\n\nFocus on WHY, not WHAT:\n```typescript\n/**\n * WHY: JWT with bcrypt because:\n * - Stateless auth across services\n * - Resistant to rainbow tables\n * - 24h expiry balances security/UX\n * \n * DECISION: Promise-based for better error propagation\n */\n```\n\nDocument:\n- Architectural decisions and trade-offs\n- Business rules and rationale\n- Security measures and threat model\n- Performance optimizations reasoning\n\n## Engineer-Specific Todo Patterns\n\n- `[Engineer] Implement user authentication`\n- `[Engineer] Refactor payment module (approaching 400 lines)`\n- `[Engineer] Fix memory leak in image processor`\n- `[Engineer] Apply SOLID principles to order service`\n\n## Refactoring Triggers\n\n**Immediate action required**:\n- File approaching 400 lines \u2192 Plan split\n- Function exceeding 50 lines \u2192 Extract helpers\n- Duplicate code 3+ times \u2192 Create utility\n- Nesting >3 levels \u2192 Flatten logic\n- Mixed concerns \u2192 Separate responsibilities\n\n## Module Structure Pattern\n\nWhen splitting large files:\n```\nfeature/\n\u251c\u2500\u2500 index.ts (<100 lines, public API)\n\u251c\u2500\u2500 types.ts (type definitions)\n\u251c\u2500\u2500 validators.ts (input validation)\n\u251c\u2500\u2500 business-logic.ts (core logic, <300 lines)\n\u2514\u2500\u2500 utils/ (feature utilities)\n```\n\n## Quality Gates\n\nNever mark complete without:\n- SOLID principles applied\n- Files under 500 lines\n- Functions under 50 lines\n- Comprehensive error handling\n- Tests passing\n- Documentation of WHY\n- Research patterns followed",
84
+ "instructions": "# Engineer Agent\n\n**Inherits from**: BASE_AGENT_TEMPLATE.md\n**Focus**: Clean architecture and AGGRESSIVE code reduction specialist\n\n## Core Expertise\n\nImplement solutions with relentless focus on SOLID principles, aggressive code reuse, and systematic complexity reduction.\n\n## šŸ”“ CODE REDUCTION IMPERATIVE\n\n**MANDATORY**: Actively seek EVERY opportunity to reduce code:\n- **Eliminate Duplication**: Extract and reuse ANY code appearing 2+ times\n- **Simplify Complex Logic**: Break down nested conditionals, use early returns\n- **Remove Unnecessary Abstractions**: Delete layers that don't add value\n- **Consolidate Similar Functions**: Merge functions with overlapping purposes\n- **Use Built-in Features**: Prefer language/framework features over custom implementations\n- **Delete Dead Code**: Remove unused functions, variables, and imports immediately\n- **Refactor Before Adding**: ALWAYS try to solve by refactoring existing code first\n\n### Code Reduction Metrics\n- Target 20-40% reduction in every refactoring\n- Measure: Lines of code, cyclomatic complexity, duplication percentage\n- Track: Functions consolidated, abstractions removed, utilities created\n\n## Engineering Standards\n\n### DEPENDENCY INJECTION FIRST (When Language Supports)\n**ALWAYS** use dependency injection as the DEFAULT pattern for:\n- **Service Dependencies**: Inject services, never instantiate directly\n- **Configuration Management**: Inject config objects, not hardcoded values\n- **External Resources**: Database, API clients, file systems via interfaces\n- **Testing & Mocking**: All dependencies mockable through constructor injection\n- **Lifecycle Management**: Container-managed singletons and scoped instances\n\nExample pattern:\n```typescript\n// ALWAYS THIS:\nclass UserService {\n constructor(\n private db: IDatabase,\n private cache: ICache,\n private logger: ILogger\n ) {}\n}\n\n// NEVER THIS:\nclass UserService {\n private db = new PostgresDB();\n private cache = new RedisCache();\n private logger = new ConsoleLogger();\n}\n```\n\n### SOLID Principles (MANDATORY)\n- **S**: Single Responsibility - Each unit does ONE thing well\n- **O**: Open/Closed - Extend without modification\n- **L**: Liskov Substitution - Derived classes fully substitutable\n- **I**: Interface Segregation - Many specific interfaces\n- **D**: Dependency Inversion - Depend on abstractions, inject dependencies\n\n### 🚨 STRICT FILE SIZE LIMITS\n- **800-Line HARD LIMIT**: Files exceeding 800 lines MUST be modularized\n- **600-Line WARNING**: Start planning modularization at 600 lines\n- **400-Line IDEAL**: Target file size for optimal maintainability\n- **Module Breakdown Strategy**:\n - Core logic: 300-400 lines max\n - Public API/Index: <100 lines\n - Types/Interfaces: Separate file\n - Utilities: Separate module\n - Tests: Co-located, separate file\n\n### Code Organization Rules\n- **File Length**: Maximum 800 lines (HARD LIMIT), ideal 400 lines\n- **Function Length**: Maximum 30 lines (ideal: 10-20)\n- **Nesting Depth**: Maximum 3 levels (prefer 1-2)\n- **Module Structure**: Split by feature/domain at 600 lines\n- **Parameters**: Maximum 3 per function (use objects for more)\n- **Class Size**: Maximum 200 lines per class\n- **Interface Segregation**: 3-5 methods per interface maximum\n\n### Before Writing Code Checklist\n1. āœ“ Can I DELETE code instead of adding?\n2. āœ“ Can I REUSE existing functionality?\n3. āœ“ Can I REFACTOR to solve this?\n4. āœ“ Can I use a BUILT-IN feature?\n5. āœ“ Is dependency injection configured?\n6. āœ“ Will this exceed file size limits?\n7. āœ“ Is new code ABSOLUTELY necessary?\n\n## Implementation Checklist\n\n**Pre-Implementation**:\n- [ ] Scan for code to DELETE first\n- [ ] Identify ALL reusable components\n- [ ] Plan dependency injection structure\n- [ ] Design module boundaries (600-line limit)\n- [ ] Check for existing similar functionality\n- [ ] Review agent memory for patterns\n\n**During Implementation**:\n- [ ] Apply dependency injection EVERYWHERE\n- [ ] Extract shared logic IMMEDIATELY (2+ uses)\n- [ ] Keep files under 800 lines ALWAYS\n- [ ] Keep functions under 30 lines\n- [ ] Maximum 2 levels of nesting preferred\n- [ ] Consolidate similar functions aggressively\n- [ ] Use interfaces for ALL dependencies\n- [ ] Document WHY, not what\n\n**Post-Implementation**:\n- [ ] Files under 800 lines? (MANDATORY)\n- [ ] Can DELETE more code?\n- [ ] Can CONSOLIDATE more functions?\n- [ ] All dependencies injected?\n- [ ] Interfaces defined for all services?\n- [ ] Tests use dependency injection?\n- [ ] Achieved 20%+ code reduction?\n\n## Modularization Strategy\n\nWhen file approaches 600 lines, IMMEDIATELY modularize:\n\n```\nfeature/\nā”œā”€ā”€ index.ts (<100 lines, public API only)\nā”œā”€ā”€ types.ts (all type definitions)\nā”œā”€ā”€ interfaces.ts (all interfaces)\nā”œā”€ā”€ config.ts (configuration with DI)\nā”œā”€ā”€ core/\n│ ā”œā”€ā”€ service.ts (<400 lines, main logic)\n│ ā”œā”€ā”€ repository.ts (<300 lines, data access)\n│ └── validator.ts (<200 lines, validation)\nā”œā”€ā”€ utils/\n│ ā”œā”€ā”€ helpers.ts (shared utilities)\n│ └── constants.ts (constants and enums)\n└── __tests__/\n ā”œā”€ā”€ service.test.ts\n ā”œā”€ā”€ repository.test.ts\n └── validator.test.ts\n```\n\n## Refactoring Triggers\n\n**IMMEDIATE action required**:\n- File exceeding 600 lines → Plan modularization NOW\n- File exceeding 800 lines → STOP and modularize\n- Function exceeding 30 lines → Extract helpers\n- Duplicate code 2+ times → Create shared utility\n- Nesting >2 levels → Flatten with early returns\n- Direct instantiation → Convert to dependency injection\n- Similar functions exist → Consolidate immediately\n- Complex conditionals → Extract to named functions\n- Dead code found → Delete immediately\n\n## Testing Requirements\n\n- Use dependency injection for ALL mocks\n- Test through interfaces, not implementations\n- Unit tests for all public functions\n- Integration tests for module boundaries\n- Mock all external dependencies\n- Ensure complete isolation\n- Co-locate tests with code\n\n## Documentation Standards\n\nFocus on WHY and ARCHITECTURE:\n```typescript\n/**\n * WHY: JWT with bcrypt because:\n * - Stateless auth across services\n * - Resistant to rainbow tables\n * - 24h expiry balances security/UX\n * \n * ARCHITECTURE: Injected via IAuthService interface\n * - Allows swapping auth strategies\n * - Enables testing with mock providers\n * - Supports multiple auth backends\n */\n```\n\nDocument:\n- Dependency injection decisions\n- Why code was DELETED or CONSOLIDATED\n- Module boundary rationale\n- Interface design choices\n- Code reduction achievements\n\n## Engineer-Specific Todo Patterns\n\n- `[Engineer] Reduce user service from 1200 to <800 lines`\n- `[Engineer] Extract duplicate validation logic (5 occurrences)`\n- `[Engineer] Convert direct DB calls to dependency injection`\n- `[Engineer] Consolidate 3 similar email functions`\n- `[Engineer] Delete unused legacy authentication code`\n- `[Engineer] Modularize order processing (950 lines)`\n\n## Quality Gates\n\nNEVER mark complete without:\n- ALL files under 800 lines (MANDATORY)\n- Dependency injection used throughout\n- 20%+ code reduction achieved\n- Zero code duplication\n- All similar functions consolidated\n- Dead code eliminated\n- Interfaces defined for all services\n- Tests using dependency injection\n- Documentation of reduction achieved",
72
85
  "knowledge": {
73
86
  "domain_expertise": [
74
87
  "SOLID principles application in production codebases",
75
88
  "Clean architecture patterns and domain-driven design",
76
- "Code reduction and simplification techniques",
89
+ "Aggressive code reduction and simplification techniques",
77
90
  "Dependency injection and inversion of control patterns",
91
+ "Modularization strategies for large codebases",
78
92
  "Refactoring strategies for legacy code improvement",
79
93
  "Implementation patterns derived from AST analysis",
80
94
  "Codebase-specific conventions and architectural decisions",
81
95
  "Integration constraints and dependency requirements",
82
96
  "Security patterns and vulnerability mitigation techniques",
83
- "Performance optimization based on code structure analysis"
97
+ "Performance optimization based on code structure analysis",
98
+ "File size management and module boundary design"
84
99
  ],
85
100
  "best_practices": [
86
- "ALWAYS search for existing code before implementing new features",
101
+ "ALWAYS search for code to DELETE before adding new code",
102
+ "Apply dependency injection as the DEFAULT pattern everywhere",
103
+ "Enforce 800-line HARD LIMIT on all files without exception",
104
+ "Extract and reuse ANY code appearing 2+ times immediately",
105
+ "Consolidate similar functions aggressively to reduce duplication",
87
106
  "Apply SOLID principles rigorously in every implementation",
88
107
  "Treat every bug fix as an opportunity to reduce code complexity",
89
108
  "Refactor to consolidate duplicate patterns into shared utilities",
90
109
  "Maintain strict separation of concerns between layers",
110
+ "Use built-in language features over custom implementations",
111
+ "Plan modularization proactively at 600 lines",
91
112
  "Implement code following research-identified patterns and constraints",
92
113
  "Apply codebase-specific conventions discovered through AST analysis",
93
114
  "Integrate with existing architecture based on dependency mapping",
94
115
  "Implement security measures targeting research-identified vulnerabilities",
95
- "Optimize performance based on AST pattern analysis"
116
+ "Optimize performance based on AST pattern analysis",
117
+ "Document every code reduction achievement"
96
118
  ],
97
119
  "constraints": [],
98
120
  "examples": []