crackerjack 0.29.0__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 (158) 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 -253
  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 +670 -0
  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 +577 -0
  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/.pre-commit-config-ai.yaml +0 -149
  151. crackerjack/.pre-commit-config-fast.yaml +0 -69
  152. crackerjack/.pre-commit-config.yaml +0 -114
  153. crackerjack/crackerjack.py +0 -4140
  154. crackerjack/pyproject.toml +0 -285
  155. crackerjack-0.29.0.dist-info/METADATA +0 -1289
  156. crackerjack-0.29.0.dist-info/RECORD +0 -17
  157. {crackerjack-0.29.0.dist-info → crackerjack-0.31.4.dist-info}/WHEEL +0 -0
  158. {crackerjack-0.29.0.dist-info → crackerjack-0.31.4.dist-info}/licenses/LICENSE +0 -0
@@ -0,0 +1,370 @@
1
+ """Refactored MCP execution tools with focused responsibilities.
2
+
3
+ This module provides the main MCP tool registration and high-level coordination.
4
+ Implementation details are delegated to specialized modules:
5
+ - workflow_executor.py: Core workflow execution logic
6
+ - error_analyzer.py: Error analysis and pattern detection
7
+ - (Additional initialization and suggestion modules as needed)
8
+
9
+ REFACTORING NOTE: Original execution_tools.py was 1110 lines with 30+ functions.
10
+ This refactored version is ~300 lines and delegates to focused modules.
11
+ """
12
+
13
+ import json
14
+ import typing as t
15
+
16
+ from crackerjack.mcp.context import get_context
17
+
18
+ from .error_analyzer import analyze_errors_with_caching
19
+ from .workflow_executor import execute_crackerjack_workflow
20
+
21
+
22
+ def register_execution_tools(mcp_app: t.Any) -> None:
23
+ """Register all execution-related MCP tools."""
24
+ _register_execute_crackerjack_tool(mcp_app)
25
+ _register_smart_error_analysis_tool(mcp_app)
26
+ _register_init_crackerjack_tool(mcp_app)
27
+ _register_agent_suggestions_tool(mcp_app)
28
+
29
+
30
+ def _register_execute_crackerjack_tool(mcp_app: t.Any) -> None:
31
+ """Register the main crackerjack execution tool."""
32
+
33
+ @mcp_app.tool()
34
+ async def execute_crackerjack(args: str, kwargs: str) -> str:
35
+ """Execute crackerjack workflow with AI agent auto-fixing."""
36
+ context = get_context()
37
+
38
+ # Validate context and rate limits
39
+ validation_error = await _validate_context_and_rate_limit(context)
40
+ if validation_error:
41
+ return validation_error
42
+
43
+ # Parse arguments
44
+ kwargs_result = _parse_kwargs(kwargs)
45
+ if "error" in kwargs_result:
46
+ return json.dumps(kwargs_result)
47
+
48
+ extra_kwargs = kwargs_result["kwargs"]
49
+
50
+ # Execute workflow
51
+ try:
52
+ result = await execute_crackerjack_workflow(args, extra_kwargs)
53
+ return json.dumps(result, indent=2)
54
+ except Exception as e:
55
+ return json.dumps(
56
+ {
57
+ "status": "failed",
58
+ "error": f"Execution failed: {e}",
59
+ "timestamp": context.get_current_time()
60
+ if hasattr(context, "get_current_time")
61
+ else None,
62
+ }
63
+ )
64
+
65
+
66
+ def _register_smart_error_analysis_tool(mcp_app: t.Any) -> None:
67
+ """Register the smart error analysis tool."""
68
+
69
+ @mcp_app.tool()
70
+ async def smart_error_analysis(use_cache: bool = True) -> str:
71
+ """Analyze cached error patterns and provide intelligent recommendations."""
72
+ context = get_context()
73
+
74
+ try:
75
+ analysis = analyze_errors_with_caching(context, use_cache)
76
+ return json.dumps(analysis, indent=2)
77
+ except Exception as e:
78
+ return json.dumps(
79
+ {
80
+ "status": "error",
81
+ "message": f"Error analysis failed: {e}",
82
+ "recommendations": [],
83
+ }
84
+ )
85
+
86
+
87
+ def _register_init_crackerjack_tool(mcp_app: t.Any) -> None:
88
+ """Register the crackerjack initialization tool."""
89
+
90
+ @mcp_app.tool()
91
+ def init_crackerjack(args: str = "", kwargs: str = "{}") -> str:
92
+ """Initialize or update crackerjack configuration in current project."""
93
+ try:
94
+ target_path, force, error = _parse_init_arguments(args, kwargs)
95
+ if error:
96
+ return _create_init_error_response(error)
97
+
98
+ result = _execute_initialization(target_path, force)
99
+ return _create_init_success_response(result)
100
+
101
+ except Exception as e:
102
+ return _create_init_exception_response(e, args)
103
+
104
+
105
+ def _register_agent_suggestions_tool(mcp_app: t.Any) -> None:
106
+ """Register the agent suggestions tool."""
107
+
108
+ @mcp_app.tool()
109
+ def suggest_agents(
110
+ task_description: str = "",
111
+ project_type: str = "python",
112
+ current_context: str = "",
113
+ ) -> str:
114
+ """Suggest appropriate Claude Code agents based on task and context."""
115
+ try:
116
+ recommendations = _generate_agent_recommendations(
117
+ task_description, project_type, current_context
118
+ )
119
+ return json.dumps(recommendations, indent=2)
120
+ except Exception as e:
121
+ return json.dumps(
122
+ {
123
+ "status": "error",
124
+ "message": f"Agent suggestion failed: {e}",
125
+ "recommendations": {},
126
+ }
127
+ )
128
+
129
+
130
+ # Helper functions for argument parsing and validation
131
+
132
+
133
+ async def _validate_context_and_rate_limit(context: t.Any) -> str | None:
134
+ """Validate MCP context and check rate limits."""
135
+ if not context:
136
+ return json.dumps({"status": "error", "message": "MCP context not available"})
137
+
138
+ # Check rate limits if available
139
+ if hasattr(context, "rate_limiter"):
140
+ from contextlib import suppress
141
+
142
+ with suppress(Exception):
143
+ allowed = await context.rate_limiter.acquire("execute_crackerjack")
144
+ if not allowed:
145
+ return json.dumps(
146
+ {
147
+ "status": "error",
148
+ "message": "Rate limit exceeded. Please wait before retrying.",
149
+ }
150
+ )
151
+
152
+ return None
153
+
154
+
155
+ def _parse_kwargs(kwargs: str) -> dict[str, t.Any]:
156
+ """Parse and validate kwargs string."""
157
+ try:
158
+ return {"kwargs": json.loads(kwargs) if kwargs.strip() else {}}
159
+ except json.JSONDecodeError as e:
160
+ return {"error": f"Invalid JSON in kwargs: {e}"}
161
+
162
+
163
+ # Initialization helper functions
164
+
165
+
166
+ def _parse_init_arguments(args: str, kwargs: str) -> tuple[t.Any, bool, str | None]:
167
+ """Parse and validate initialization arguments."""
168
+ try:
169
+ target_path = args.strip() or "."
170
+ kwargs_dict = json.loads(kwargs) if kwargs.strip() else {}
171
+ force = kwargs_dict.get("force") or False
172
+
173
+ from pathlib import Path
174
+
175
+ path_obj = Path(target_path)
176
+
177
+ return path_obj, force, None
178
+
179
+ except json.JSONDecodeError:
180
+ return None, False, "Invalid JSON in kwargs parameter"
181
+ except Exception as e:
182
+ return None, False, f"Invalid arguments: {e}"
183
+
184
+
185
+ def _execute_initialization(target_path: t.Any, force: bool) -> dict[str, t.Any]:
186
+ """Execute crackerjack initialization."""
187
+ from rich.console import Console
188
+
189
+ from crackerjack.services.initialization import InitializationService
190
+
191
+ console = Console()
192
+
193
+ return InitializationService(console, target_path).initialize_project(
194
+ force_update=force
195
+ )
196
+
197
+
198
+ def _create_init_error_response(message: str) -> str:
199
+ """Create initialization error response."""
200
+ return json.dumps(
201
+ {
202
+ "status": "error",
203
+ "message": message,
204
+ "initialized": False,
205
+ }
206
+ )
207
+
208
+
209
+ def _create_init_success_response(result: dict[str, t.Any]) -> str:
210
+ """Create initialization success response."""
211
+ return json.dumps(
212
+ {
213
+ "status": "success",
214
+ "message": "Crackerjack configuration initialized successfully",
215
+ "result": result,
216
+ "initialized": True,
217
+ },
218
+ indent=2,
219
+ )
220
+
221
+
222
+ def _create_init_exception_response(error: Exception, target_path: t.Any) -> str:
223
+ """Create initialization exception response."""
224
+ return json.dumps(
225
+ {
226
+ "status": "error",
227
+ "message": f"Initialization failed: {error}",
228
+ "target_path": str(target_path),
229
+ "initialized": False,
230
+ }
231
+ )
232
+
233
+
234
+ # Agent suggestion helper functions
235
+
236
+
237
+ def _generate_agent_recommendations(
238
+ task_description: str, project_type: str, current_context: str
239
+ ) -> dict[str, t.Any]:
240
+ """Generate agent recommendations based on task context."""
241
+ recommendations = {
242
+ "status": "success",
243
+ "task_analysis": {
244
+ "description": task_description,
245
+ "project_type": project_type,
246
+ "context": current_context,
247
+ },
248
+ "suggested_agents": [],
249
+ "workflow_recommendations": [],
250
+ "reasoning": "",
251
+ }
252
+
253
+ # Analyze task and context
254
+ suggestions = _analyze_task_for_agents(
255
+ task_description, project_type, current_context
256
+ )
257
+ recommendations["suggested_agents"] = suggestions["agents"]
258
+ recommendations["workflow_recommendations"] = suggestions["workflows"]
259
+ recommendations["reasoning"] = suggestions["reasoning"]
260
+
261
+ return recommendations
262
+
263
+
264
+ def _analyze_task_for_agents(
265
+ task_description: str, project_type: str, current_context: str
266
+ ) -> dict[str, t.Any]:
267
+ """Analyze task description to determine appropriate agents."""
268
+ agents = []
269
+ workflows = []
270
+ reasoning_parts = []
271
+
272
+ task_lower = task_description.lower()
273
+ current_context.lower()
274
+
275
+ # Code quality and testing agents
276
+ if any(keyword in task_lower for keyword in ("test", "quality", "fix", "error")):
277
+ agents.extend(
278
+ [
279
+ {
280
+ "name": "TestCreationAgent",
281
+ "reason": "Task involves testing or quality assurance",
282
+ "confidence": 0.8,
283
+ },
284
+ {
285
+ "name": "RefactoringAgent",
286
+ "reason": "Code quality improvements often require refactoring",
287
+ "confidence": 0.7,
288
+ },
289
+ ]
290
+ )
291
+ reasoning_parts.append("Task involves testing or quality improvement")
292
+
293
+ # Security-related tasks
294
+ if any(
295
+ keyword in task_lower for keyword in ("security", "vulnerability", "secure")
296
+ ):
297
+ agents.append(
298
+ {
299
+ "name": "SecurityAgent",
300
+ "reason": "Task involves security considerations",
301
+ "confidence": 0.9,
302
+ }
303
+ )
304
+ reasoning_parts.append("Security concerns detected")
305
+
306
+ # Performance optimization
307
+ if any(
308
+ keyword in task_lower
309
+ for keyword in ("performance", "optimize", "speed", "slow")
310
+ ):
311
+ agents.append(
312
+ {
313
+ "name": "PerformanceAgent",
314
+ "reason": "Task involves performance optimization",
315
+ "confidence": 0.8,
316
+ }
317
+ )
318
+ reasoning_parts.append("Performance optimization required")
319
+
320
+ # Documentation tasks
321
+ if any(
322
+ keyword in task_lower for keyword in ("document", "readme", "doc", "explain")
323
+ ):
324
+ agents.append(
325
+ {
326
+ "name": "DocumentationAgent",
327
+ "reason": "Task involves documentation work",
328
+ "confidence": 0.8,
329
+ }
330
+ )
331
+ reasoning_parts.append("Documentation work identified")
332
+
333
+ # Import and dependency management
334
+ if any(
335
+ keyword in task_lower
336
+ for keyword in ("import", "dependency", "package", "module")
337
+ ):
338
+ agents.append(
339
+ {
340
+ "name": "ImportOptimizationAgent",
341
+ "reason": "Task involves import or dependency management",
342
+ "confidence": 0.7,
343
+ }
344
+ )
345
+ reasoning_parts.append("Import/dependency work detected")
346
+
347
+ # Project type specific suggestions
348
+ if project_type == "python":
349
+ workflows.extend(
350
+ [
351
+ "Run quality checks with AI agent auto-fixing",
352
+ "Use comprehensive testing with coverage tracking",
353
+ "Apply refactoring for code clarity",
354
+ ]
355
+ )
356
+
357
+ # Default fallback
358
+ if not agents:
359
+ agents.append(
360
+ {
361
+ "name": "RefactoringAgent",
362
+ "reason": "Default agent for general code improvement tasks",
363
+ "confidence": 0.5,
364
+ }
365
+ )
366
+ reasoning_parts.append("General code improvement task")
367
+
368
+ reasoning = "; ".join(reasoning_parts)
369
+
370
+ return {"agents": agents, "workflows": workflows, "reasoning": reasoning}