crackerjack 0.30.3__py3-none-any.whl → 0.31.4__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.

Potentially problematic release.


This version of crackerjack might be problematic. Click here for more details.

Files changed (155) hide show
  1. crackerjack/CLAUDE.md +1005 -0
  2. crackerjack/RULES.md +380 -0
  3. crackerjack/__init__.py +42 -13
  4. crackerjack/__main__.py +225 -299
  5. crackerjack/agents/__init__.py +41 -0
  6. crackerjack/agents/architect_agent.py +281 -0
  7. crackerjack/agents/base.py +169 -0
  8. crackerjack/agents/coordinator.py +512 -0
  9. crackerjack/agents/documentation_agent.py +498 -0
  10. crackerjack/agents/dry_agent.py +388 -0
  11. crackerjack/agents/formatting_agent.py +245 -0
  12. crackerjack/agents/import_optimization_agent.py +281 -0
  13. crackerjack/agents/performance_agent.py +669 -0
  14. crackerjack/agents/proactive_agent.py +104 -0
  15. crackerjack/agents/refactoring_agent.py +788 -0
  16. crackerjack/agents/security_agent.py +529 -0
  17. crackerjack/agents/test_creation_agent.py +652 -0
  18. crackerjack/agents/test_specialist_agent.py +486 -0
  19. crackerjack/agents/tracker.py +212 -0
  20. crackerjack/api.py +560 -0
  21. crackerjack/cli/__init__.py +24 -0
  22. crackerjack/cli/facade.py +104 -0
  23. crackerjack/cli/handlers.py +267 -0
  24. crackerjack/cli/interactive.py +471 -0
  25. crackerjack/cli/options.py +401 -0
  26. crackerjack/cli/utils.py +18 -0
  27. crackerjack/code_cleaner.py +618 -928
  28. crackerjack/config/__init__.py +19 -0
  29. crackerjack/config/hooks.py +218 -0
  30. crackerjack/core/__init__.py +0 -0
  31. crackerjack/core/async_workflow_orchestrator.py +406 -0
  32. crackerjack/core/autofix_coordinator.py +200 -0
  33. crackerjack/core/container.py +104 -0
  34. crackerjack/core/enhanced_container.py +542 -0
  35. crackerjack/core/performance.py +243 -0
  36. crackerjack/core/phase_coordinator.py +561 -0
  37. crackerjack/core/proactive_workflow.py +316 -0
  38. crackerjack/core/session_coordinator.py +289 -0
  39. crackerjack/core/workflow_orchestrator.py +640 -0
  40. crackerjack/dynamic_config.py +94 -103
  41. crackerjack/errors.py +263 -41
  42. crackerjack/executors/__init__.py +11 -0
  43. crackerjack/executors/async_hook_executor.py +431 -0
  44. crackerjack/executors/cached_hook_executor.py +242 -0
  45. crackerjack/executors/hook_executor.py +345 -0
  46. crackerjack/executors/individual_hook_executor.py +669 -0
  47. crackerjack/intelligence/__init__.py +44 -0
  48. crackerjack/intelligence/adaptive_learning.py +751 -0
  49. crackerjack/intelligence/agent_orchestrator.py +551 -0
  50. crackerjack/intelligence/agent_registry.py +414 -0
  51. crackerjack/intelligence/agent_selector.py +502 -0
  52. crackerjack/intelligence/integration.py +290 -0
  53. crackerjack/interactive.py +576 -315
  54. crackerjack/managers/__init__.py +11 -0
  55. crackerjack/managers/async_hook_manager.py +135 -0
  56. crackerjack/managers/hook_manager.py +137 -0
  57. crackerjack/managers/publish_manager.py +411 -0
  58. crackerjack/managers/test_command_builder.py +151 -0
  59. crackerjack/managers/test_executor.py +435 -0
  60. crackerjack/managers/test_manager.py +258 -0
  61. crackerjack/managers/test_manager_backup.py +1124 -0
  62. crackerjack/managers/test_progress.py +144 -0
  63. crackerjack/mcp/__init__.py +0 -0
  64. crackerjack/mcp/cache.py +336 -0
  65. crackerjack/mcp/client_runner.py +104 -0
  66. crackerjack/mcp/context.py +615 -0
  67. crackerjack/mcp/dashboard.py +636 -0
  68. crackerjack/mcp/enhanced_progress_monitor.py +479 -0
  69. crackerjack/mcp/file_monitor.py +336 -0
  70. crackerjack/mcp/progress_components.py +569 -0
  71. crackerjack/mcp/progress_monitor.py +949 -0
  72. crackerjack/mcp/rate_limiter.py +332 -0
  73. crackerjack/mcp/server.py +22 -0
  74. crackerjack/mcp/server_core.py +244 -0
  75. crackerjack/mcp/service_watchdog.py +501 -0
  76. crackerjack/mcp/state.py +395 -0
  77. crackerjack/mcp/task_manager.py +257 -0
  78. crackerjack/mcp/tools/__init__.py +17 -0
  79. crackerjack/mcp/tools/core_tools.py +249 -0
  80. crackerjack/mcp/tools/error_analyzer.py +308 -0
  81. crackerjack/mcp/tools/execution_tools.py +370 -0
  82. crackerjack/mcp/tools/execution_tools_backup.py +1097 -0
  83. crackerjack/mcp/tools/intelligence_tool_registry.py +80 -0
  84. crackerjack/mcp/tools/intelligence_tools.py +314 -0
  85. crackerjack/mcp/tools/monitoring_tools.py +502 -0
  86. crackerjack/mcp/tools/proactive_tools.py +384 -0
  87. crackerjack/mcp/tools/progress_tools.py +141 -0
  88. crackerjack/mcp/tools/utility_tools.py +341 -0
  89. crackerjack/mcp/tools/workflow_executor.py +360 -0
  90. crackerjack/mcp/websocket/__init__.py +14 -0
  91. crackerjack/mcp/websocket/app.py +39 -0
  92. crackerjack/mcp/websocket/endpoints.py +559 -0
  93. crackerjack/mcp/websocket/jobs.py +253 -0
  94. crackerjack/mcp/websocket/server.py +116 -0
  95. crackerjack/mcp/websocket/websocket_handler.py +78 -0
  96. crackerjack/mcp/websocket_server.py +10 -0
  97. crackerjack/models/__init__.py +31 -0
  98. crackerjack/models/config.py +93 -0
  99. crackerjack/models/config_adapter.py +230 -0
  100. crackerjack/models/protocols.py +118 -0
  101. crackerjack/models/task.py +154 -0
  102. crackerjack/monitoring/ai_agent_watchdog.py +450 -0
  103. crackerjack/monitoring/regression_prevention.py +638 -0
  104. crackerjack/orchestration/__init__.py +0 -0
  105. crackerjack/orchestration/advanced_orchestrator.py +970 -0
  106. crackerjack/orchestration/execution_strategies.py +341 -0
  107. crackerjack/orchestration/test_progress_streamer.py +636 -0
  108. crackerjack/plugins/__init__.py +15 -0
  109. crackerjack/plugins/base.py +200 -0
  110. crackerjack/plugins/hooks.py +246 -0
  111. crackerjack/plugins/loader.py +335 -0
  112. crackerjack/plugins/managers.py +259 -0
  113. crackerjack/py313.py +8 -3
  114. crackerjack/services/__init__.py +22 -0
  115. crackerjack/services/cache.py +314 -0
  116. crackerjack/services/config.py +347 -0
  117. crackerjack/services/config_integrity.py +99 -0
  118. crackerjack/services/contextual_ai_assistant.py +516 -0
  119. crackerjack/services/coverage_ratchet.py +347 -0
  120. crackerjack/services/debug.py +736 -0
  121. crackerjack/services/dependency_monitor.py +617 -0
  122. crackerjack/services/enhanced_filesystem.py +439 -0
  123. crackerjack/services/file_hasher.py +151 -0
  124. crackerjack/services/filesystem.py +395 -0
  125. crackerjack/services/git.py +165 -0
  126. crackerjack/services/health_metrics.py +611 -0
  127. crackerjack/services/initialization.py +847 -0
  128. crackerjack/services/log_manager.py +286 -0
  129. crackerjack/services/logging.py +174 -0
  130. crackerjack/services/metrics.py +578 -0
  131. crackerjack/services/pattern_cache.py +362 -0
  132. crackerjack/services/pattern_detector.py +515 -0
  133. crackerjack/services/performance_benchmarks.py +653 -0
  134. crackerjack/services/security.py +163 -0
  135. crackerjack/services/server_manager.py +234 -0
  136. crackerjack/services/smart_scheduling.py +144 -0
  137. crackerjack/services/tool_version_service.py +61 -0
  138. crackerjack/services/unified_config.py +437 -0
  139. crackerjack/services/version_checker.py +248 -0
  140. crackerjack/slash_commands/__init__.py +14 -0
  141. crackerjack/slash_commands/init.md +122 -0
  142. crackerjack/slash_commands/run.md +163 -0
  143. crackerjack/slash_commands/status.md +127 -0
  144. crackerjack-0.31.4.dist-info/METADATA +742 -0
  145. crackerjack-0.31.4.dist-info/RECORD +148 -0
  146. crackerjack-0.31.4.dist-info/entry_points.txt +2 -0
  147. crackerjack/.gitignore +0 -34
  148. crackerjack/.libcst.codemod.yaml +0 -18
  149. crackerjack/.pdm.toml +0 -1
  150. crackerjack/crackerjack.py +0 -3805
  151. crackerjack/pyproject.toml +0 -286
  152. crackerjack-0.30.3.dist-info/METADATA +0 -1290
  153. crackerjack-0.30.3.dist-info/RECORD +0 -16
  154. {crackerjack-0.30.3.dist-info → crackerjack-0.31.4.dist-info}/WHEEL +0 -0
  155. {crackerjack-0.30.3.dist-info → crackerjack-0.31.4.dist-info}/licenses/LICENSE +0 -0
@@ -0,0 +1,290 @@
1
+ """Integration layer for Intelligent Agent Selection System.
2
+
3
+ Provides high-level API for integrating the intelligent agent system with
4
+ existing crackerjack workflows and MCP tools.
5
+ """
6
+
7
+ import logging
8
+ import typing as t
9
+ from dataclasses import dataclass
10
+
11
+ from crackerjack.agents.base import AgentContext, FixResult, Issue
12
+
13
+ from .adaptive_learning import get_learning_system
14
+ from .agent_orchestrator import (
15
+ ExecutionRequest,
16
+ ExecutionStrategy,
17
+ get_agent_orchestrator,
18
+ )
19
+ from .agent_registry import get_agent_registry
20
+ from .agent_selector import TaskContext, TaskDescription
21
+
22
+
23
+ @dataclass
24
+ class SmartAgentResult:
25
+ """Result from smart agent execution."""
26
+
27
+ success: bool
28
+ result: t.Any
29
+ agents_used: list[str]
30
+ execution_time: float
31
+ confidence: float
32
+ recommendations: list[str]
33
+ learning_applied: bool = False
34
+
35
+
36
+ class IntelligentAgentSystem:
37
+ """High-level interface to the intelligent agent system."""
38
+
39
+ def __init__(self) -> None:
40
+ self.logger = logging.getLogger(__name__)
41
+ self._initialized = False
42
+
43
+ async def initialize(self) -> None:
44
+ """Initialize the intelligent agent system."""
45
+ if self._initialized:
46
+ return
47
+
48
+ self.logger.info("Initializing Intelligent Agent System")
49
+
50
+ # Initialize all components
51
+ self.registry = await get_agent_registry()
52
+ self.orchestrator = await get_agent_orchestrator()
53
+ self.learning_system = await get_learning_system()
54
+
55
+ self._initialized = True
56
+
57
+ # Log system status
58
+ stats = self.registry.get_agent_stats()
59
+ self.logger.info(
60
+ f"System initialized: {stats['total_agents']} agents available "
61
+ f"({stats['by_source']})"
62
+ )
63
+
64
+ async def execute_smart_task(
65
+ self,
66
+ description: str,
67
+ context: TaskContext | None = None,
68
+ strategy: ExecutionStrategy = ExecutionStrategy.SINGLE_BEST,
69
+ context_data: AgentContext | None = None,
70
+ ) -> SmartAgentResult:
71
+ """Execute a task using intelligent agent selection."""
72
+ await self.initialize()
73
+
74
+ # Create task description
75
+ task = TaskDescription(
76
+ description=description,
77
+ context=context,
78
+ )
79
+
80
+ # Get learning recommendations
81
+ candidates = await self.orchestrator.selector.select_agents(
82
+ task, max_candidates=5
83
+ )
84
+ candidate_names = [c.agent.metadata.name for c in candidates]
85
+
86
+ learning_recommendations = self.learning_system.get_agent_recommendations(
87
+ task, candidate_names
88
+ )
89
+
90
+ # Apply learning to boost scores
91
+ for candidate in candidates:
92
+ agent_name = candidate.agent.metadata.name
93
+ if agent_name in learning_recommendations:
94
+ learning_boost = (
95
+ learning_recommendations[agent_name] * 0.2
96
+ ) # 20% boost max
97
+ candidate.final_score = min(1.0, candidate.final_score + learning_boost)
98
+
99
+ # Re-sort by updated scores
100
+ candidates.sort(key=lambda c: c.final_score, reverse=True)
101
+
102
+ # Create execution request
103
+ request = ExecutionRequest(
104
+ task=task,
105
+ strategy=strategy,
106
+ max_agents=min(3, len(candidates)),
107
+ context=context_data,
108
+ )
109
+
110
+ # Execute with orchestrator
111
+ result = await self.orchestrator.execute(request)
112
+
113
+ # Record results for learning
114
+ if candidates:
115
+ best_candidate = candidates[0]
116
+ await self.learning_system.record_execution(
117
+ agent=best_candidate.agent,
118
+ task=task,
119
+ success=result.success,
120
+ execution_time=result.execution_time,
121
+ agent_score=best_candidate,
122
+ error_message=result.error_message,
123
+ )
124
+
125
+ # Create smart result
126
+ return SmartAgentResult(
127
+ success=result.success,
128
+ result=result.primary_result,
129
+ agents_used=result.agents_used,
130
+ execution_time=result.execution_time,
131
+ confidence=candidates[0].final_score if candidates else 0.0,
132
+ recommendations=result.recommendations or [],
133
+ learning_applied=bool(learning_recommendations),
134
+ )
135
+
136
+ async def handle_crackerjack_issue(
137
+ self,
138
+ issue: Issue,
139
+ context: AgentContext,
140
+ use_learning: bool = True,
141
+ ) -> FixResult:
142
+ """Handle a crackerjack Issue using intelligent agent selection."""
143
+ await self.initialize()
144
+
145
+ # Convert issue to task description
146
+ task_context = self._map_issue_to_task_context(issue)
147
+
148
+ task = TaskDescription(
149
+ description=f"Fix {issue.type.value} issue: {issue.message}",
150
+ context=task_context,
151
+ error_types=[issue.type.value],
152
+ priority=self._map_severity_to_priority(issue.severity),
153
+ )
154
+
155
+ # Execute smart task
156
+ smart_result = await self.execute_smart_task(
157
+ description=task.description,
158
+ context=task_context,
159
+ context_data=context,
160
+ )
161
+
162
+ # Convert result back to FixResult
163
+ if smart_result.success and isinstance(smart_result.result, FixResult):
164
+ return smart_result.result
165
+
166
+ # Create fallback FixResult
167
+ return FixResult(
168
+ success=smart_result.success,
169
+ confidence=smart_result.confidence,
170
+ remaining_issues=[issue.message] if not smart_result.success else [],
171
+ recommendations=smart_result.recommendations,
172
+ fixes_applied=[
173
+ f"Applied using intelligent agent: {', '.join(smart_result.agents_used)}"
174
+ ]
175
+ if smart_result.success
176
+ else [],
177
+ )
178
+
179
+ async def get_best_agent_for_task(
180
+ self,
181
+ description: str,
182
+ context: TaskContext | None = None,
183
+ ) -> tuple[str, float] | None:
184
+ """Get the best agent for a task without executing it."""
185
+ await self.initialize()
186
+
187
+ task = TaskDescription(description=description, context=context)
188
+ best_candidate = await self.orchestrator.selector.select_best_agent(task)
189
+
190
+ if best_candidate:
191
+ return best_candidate.agent.metadata.name, best_candidate.final_score
192
+ return None
193
+
194
+ async def analyze_task_complexity(self, description: str) -> dict[str, t.Any]:
195
+ """Analyze a task's complexity and provide recommendations."""
196
+ await self.initialize()
197
+
198
+ task = TaskDescription(description=description)
199
+ return await self.orchestrator.selector.analyze_task_complexity(task)
200
+
201
+ def _map_issue_to_task_context(self, issue: Issue) -> TaskContext | None:
202
+ """Map crackerjack Issue type to TaskContext."""
203
+ from crackerjack.agents.base import IssueType
204
+
205
+ mapping = {
206
+ IssueType.COMPLEXITY: TaskContext.REFACTORING,
207
+ IssueType.DRY_VIOLATION: TaskContext.REFACTORING,
208
+ IssueType.PERFORMANCE: TaskContext.PERFORMANCE,
209
+ IssueType.SECURITY: TaskContext.SECURITY,
210
+ IssueType.TEST_FAILURE: TaskContext.TESTING,
211
+ IssueType.FORMATTING: TaskContext.CODE_QUALITY,
212
+ IssueType.IMPORT_ERROR: TaskContext.CODE_QUALITY,
213
+ IssueType.TYPE_ERROR: TaskContext.CODE_QUALITY,
214
+ IssueType.DOCUMENTATION: TaskContext.DOCUMENTATION,
215
+ IssueType.DEAD_CODE: TaskContext.REFACTORING,
216
+ IssueType.DEPENDENCY: TaskContext.CODE_QUALITY,
217
+ IssueType.TEST_ORGANIZATION: TaskContext.TESTING,
218
+ }
219
+
220
+ return mapping.get(issue.type) or TaskContext.GENERAL
221
+
222
+ def _map_severity_to_priority(self, severity: t.Any) -> int:
223
+ """Map crackerjack Priority to task priority."""
224
+ from crackerjack.agents.base import Priority
225
+
226
+ mapping = {
227
+ Priority.HIGH: 90,
228
+ Priority.MEDIUM: 60,
229
+ Priority.LOW: 30,
230
+ }
231
+
232
+ return mapping.get(severity) or 50
233
+
234
+ async def get_system_status(self) -> dict[str, t.Any]:
235
+ """Get comprehensive system status."""
236
+ await self.initialize()
237
+
238
+ registry_stats = self.registry.get_agent_stats()
239
+ orchestrator_stats = self.orchestrator.get_execution_stats()
240
+ learning_summary = self.learning_system.get_learning_summary()
241
+
242
+ return {
243
+ "initialized": self._initialized,
244
+ "registry": registry_stats,
245
+ "orchestration": orchestrator_stats,
246
+ "learning": learning_summary,
247
+ }
248
+
249
+
250
+ # Global intelligent agent system
251
+ _intelligent_system_instance: IntelligentAgentSystem | None = None
252
+
253
+
254
+ async def get_intelligent_agent_system() -> IntelligentAgentSystem:
255
+ """Get or create the global intelligent agent system."""
256
+ global _intelligent_system_instance
257
+
258
+ if _intelligent_system_instance is None:
259
+ _intelligent_system_instance = IntelligentAgentSystem()
260
+
261
+ return _intelligent_system_instance
262
+
263
+
264
+ # Convenience functions for common use cases
265
+ async def smart_fix_issue(
266
+ issue: Issue,
267
+ context: AgentContext,
268
+ ) -> FixResult:
269
+ """Fix an issue using intelligent agent selection."""
270
+ system = await get_intelligent_agent_system()
271
+ return await system.handle_crackerjack_issue(issue, context)
272
+
273
+
274
+ async def smart_execute_task(
275
+ description: str,
276
+ context: TaskContext | None = None,
277
+ strategy: ExecutionStrategy = ExecutionStrategy.SINGLE_BEST,
278
+ ) -> SmartAgentResult:
279
+ """Execute a task using intelligent agent selection."""
280
+ system = await get_intelligent_agent_system()
281
+ return await system.execute_smart_task(description, context, strategy)
282
+
283
+
284
+ async def get_smart_recommendation(
285
+ description: str,
286
+ context: TaskContext | None = None,
287
+ ) -> tuple[str, float] | None:
288
+ """Get a smart agent recommendation without executing."""
289
+ system = await get_intelligent_agent_system()
290
+ return await system.get_best_agent_for_task(description, context)