mdan-cli 2.6.0 → 2.7.0

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.
@@ -0,0 +1,534 @@
1
+ """Skill Router - Intelligent skill detection and execution
2
+
3
+ Detects required skills for tasks and executes them using appropriate agents.
4
+ """
5
+
6
+ import re
7
+ import os
8
+ from pathlib import Path
9
+ from typing import Dict, Any, Optional, List, Set
10
+ from enum import Enum
11
+
12
+ from .orchestrator import CrewAIOrchestrator
13
+
14
+
15
+ class Skill(Enum):
16
+ """Available skills."""
17
+
18
+ # Product skills
19
+ REQUIREMENT_ANALYSIS = "requirement_analysis"
20
+ PRD_CREATION = "prd_creation"
21
+ USER_STORY_WRITING = "user_story_writing"
22
+ PERSONA_CREATION = "persona_creation"
23
+ FEATURE_PRIORITIZATION = "feature_prioritization"
24
+ ACCEPTANCE_CRITERIA = "acceptance_criteria"
25
+
26
+ # Architecture skills
27
+ SYSTEM_ARCHITECTURE = "system_architecture"
28
+ TECH_STACK_SELECTION = "tech_stack_selection"
29
+ ADR_DOCUMENTATION = "adr_documentation"
30
+ API_DESIGN = "api_design"
31
+ DATABASE_SCHEMA = "database_schema"
32
+
33
+ # UX skills
34
+ USER_FLOW_DESIGN = "user_flow_design"
35
+ WIREFRAME_CREATION = "wireframe_creation"
36
+ DESIGN_SYSTEM = "design_system"
37
+ ACCESSIBILITY = "accessibility"
38
+ PROTOTYPE_CREATION = "prototype_creation"
39
+
40
+ # Development skills
41
+ IMPLEMENTATION = "implementation"
42
+ REFACTORING = "refactoring"
43
+ CODE_REVIEW = "code_review"
44
+ TESTING = "testing"
45
+ DEBUGGING = "debugging"
46
+
47
+ # Testing skills
48
+ TEST_STRATEGY = "test_strategy"
49
+ UNIT_TESTING = "unit_testing"
50
+ INTEGRATION_TESTING = "integration_testing"
51
+ E2E_TESTING = "e2e_testing"
52
+ TEST_EXECUTION = "test_execution"
53
+ PERFORMANCE_TESTING = "performance_testing"
54
+ SECURITY_TESTING = "security_testing"
55
+ TEST_AUTOMATION = "test_automation"
56
+ QUALITY_GATE = "quality_gate"
57
+
58
+ # Security skills
59
+ SECURITY_REVIEW = "security_review"
60
+ VULNERABILITY_SCAN = "vulnerability_scan"
61
+ SECURE_CODING = "secure_coding"
62
+ DEPENDENCY_SECURITY = "dependency_security"
63
+ AUTHENTICATION_SECURITY = "authentication_security"
64
+ DATA_PROTECTION = "data_protection"
65
+ API_SECURITY = "api_security"
66
+ SECURITY_MONITORING = "security_monitoring"
67
+ COMPLIANCE_REVIEW = "compliance_review"
68
+
69
+ # DevOps skills
70
+ CI_CD_PIPELINE = "ci_cd_pipeline"
71
+ DOCKER_SETUP = "docker_setup"
72
+ KUBERNETES_SETUP = "kubernetes_setup"
73
+ AZURE_DEPLOYMENT = "azure_deployment"
74
+ MONITORING_SETUP = "monitoring_setup"
75
+ DEPLOYMENT_STRATEGY = "deployment_strategy"
76
+ INFRASTRUCTURE_AS_CODE = "infrastructure_as_code"
77
+ BACKUP_RECOVERY = "backup_recovery"
78
+ SCALING_STRATEGY = "scaling_strategy"
79
+ SECURITY_HARDENING = "security_hardening"
80
+
81
+ # Documentation skills
82
+ README_CREATION = "readme_creation"
83
+ API_DOCUMENTATION = "api_documentation"
84
+ USER_GUIDE = "user_guide"
85
+ DEVELOPER_GUIDE = "developer_guide"
86
+ ARCHITECTURE_DOCUMENTATION = "architecture_documentation"
87
+ CHANGELOG = "changelog"
88
+ TROUBLESHOOTING_GUIDE = "troubleshooting_guide"
89
+ MIGRATION_GUIDE = "migration_guide"
90
+ CODE_EXAMPLES = "code_examples"
91
+ RELEASE_NOTES = "release_notes"
92
+
93
+ # Tool skills
94
+ WEB_SEARCH = "web_search"
95
+ SQL_QUERY = "sql_query"
96
+ FILE_OPERATION = "file_operation"
97
+
98
+
99
+ class SkillRouter:
100
+ """Intelligent skill router for detecting and executing skills."""
101
+
102
+ def __init__(self, orchestrator: CrewAIOrchestrator):
103
+ """Initialize Skill Router.
104
+
105
+ Args:
106
+ orchestrator: CrewAI orchestrator instance
107
+ """
108
+ self.orchestrator = orchestrator
109
+ self.skill_patterns = self._initialize_skill_patterns()
110
+ self.skill_execution_history = []
111
+
112
+ def _initialize_skill_patterns(self) -> Dict[Skill, List[str]]:
113
+ """Initialize skill detection patterns.
114
+
115
+ Returns:
116
+ Dictionary mapping skills to keyword patterns
117
+ """
118
+ return {
119
+ # Product skills
120
+ Skill.REQUIREMENT_ANALYSIS: [
121
+ "requirement",
122
+ "analyze requirement",
123
+ "gather requirement",
124
+ ],
125
+ Skill.PRD_CREATION: ["prd", "product requirement", "requirement document"],
126
+ Skill.USER_STORY_WRITING: [
127
+ "user story",
128
+ "story",
129
+ "as a user",
130
+ "user wants",
131
+ ],
132
+ Skill.PERSONA_CREATION: [
133
+ "persona",
134
+ "user persona",
135
+ "target audience",
136
+ "user profile",
137
+ ],
138
+ Skill.FEATURE_PRIORITIZATION: [
139
+ "prioritize feature",
140
+ "feature priority",
141
+ "rank feature",
142
+ "moscow",
143
+ ],
144
+ Skill.ACCEPTANCE_CRITERIA: [
145
+ "acceptance criteria",
146
+ "definition of done",
147
+ "dod",
148
+ ],
149
+ # Architecture skills
150
+ Skill.SYSTEM_ARCHITECTURE: [
151
+ "architecture",
152
+ "system design",
153
+ "high level design",
154
+ ],
155
+ Skill.TECH_STACK_SELECTION: [
156
+ "tech stack",
157
+ "technology stack",
158
+ "framework",
159
+ "library",
160
+ ],
161
+ Skill.ADR_DOCUMENTATION: [
162
+ "adr",
163
+ "architecture decision",
164
+ "decision record",
165
+ ],
166
+ Skill.API_DESIGN: ["api design", "endpoint", "rest api", "graphql"],
167
+ Skill.DATABASE_SCHEMA: [
168
+ "database schema",
169
+ "data model",
170
+ "entity relationship",
171
+ "er diagram",
172
+ ],
173
+ # UX skills
174
+ Skill.USER_FLOW_DESIGN: ["user flow", "flow", "journey", "workflow"],
175
+ Skill.WIREFRAME_CREATION: ["wireframe", "mockup", "layout"],
176
+ Skill.DESIGN_SYSTEM: ["design system", "component library", "style guide"],
177
+ Skill.ACCESSIBILITY: ["accessibility", "a11y", "wcag", "inclusive design"],
178
+ Skill.PROTOTYPE_CREATION: [
179
+ "prototype",
180
+ "interactive prototype",
181
+ "clickable",
182
+ ],
183
+ # Development skills
184
+ Skill.IMPLEMENTATION: [
185
+ "implement",
186
+ "develop",
187
+ "code",
188
+ "build",
189
+ "create feature",
190
+ ],
191
+ Skill.REFACTORING: [
192
+ "refactor",
193
+ "clean up",
194
+ "improve code",
195
+ "optimize code",
196
+ ],
197
+ Skill.CODE_REVIEW: ["code review", "review code", "peer review"],
198
+ Skill.TESTING: ["write test", "create test", "add test"],
199
+ Skill.DEBUGGING: ["debug", "fix bug", "troubleshoot", "resolve issue"],
200
+ # Testing skills
201
+ Skill.TEST_STRATEGY: ["test strategy", "testing approach", "test plan"],
202
+ Skill.UNIT_TESTING: ["unit test", "unit testing", "test function"],
203
+ Skill.INTEGRATION_TESTING: [
204
+ "integration test",
205
+ "api test",
206
+ "database test",
207
+ ],
208
+ Skill.E2E_TESTING: ["e2e test", "end to end test", "user flow test"],
209
+ Skill.TEST_EXECUTION: ["run test", "execute test", "test execution"],
210
+ Skill.PERFORMANCE_TESTING: ["performance test", "load test", "stress test"],
211
+ Skill.SECURITY_TESTING: [
212
+ "security test",
213
+ "penetration test",
214
+ "vulnerability test",
215
+ ],
216
+ Skill.TEST_AUTOMATION: ["test automation", "automate test", "ci test"],
217
+ Skill.QUALITY_GATE: ["quality gate", "quality check", "acceptance gate"],
218
+ # Security skills
219
+ Skill.SECURITY_REVIEW: [
220
+ "security review",
221
+ "security audit",
222
+ "code security",
223
+ ],
224
+ Skill.VULNERABILITY_SCAN: [
225
+ "vulnerability scan",
226
+ "security scan",
227
+ "dependency scan",
228
+ ],
229
+ Skill.SECURE_CODING: [
230
+ "secure coding",
231
+ "security best practice",
232
+ "secure code",
233
+ ],
234
+ Skill.DEPENDENCY_SECURITY: [
235
+ "dependency security",
236
+ "vulnerable dependency",
237
+ "supply chain",
238
+ ],
239
+ Skill.AUTHENTICATION_SECURITY: [
240
+ "authentication",
241
+ "authorization",
242
+ "auth",
243
+ "oauth",
244
+ "jwt",
245
+ ],
246
+ Skill.DATA_PROTECTION: ["data protection", "encryption", "gdpr", "privacy"],
247
+ Skill.API_SECURITY: ["api security", "rate limiting", "api key"],
248
+ Skill.SECURITY_MONITORING: [
249
+ "security monitoring",
250
+ "security alert",
251
+ "intrusion detection",
252
+ ],
253
+ Skill.COMPLIANCE_REVIEW: ["compliance", "audit", "regulation", "standard"],
254
+ # DevOps skills
255
+ Skill.CI_CD_PIPELINE: [
256
+ "ci/cd",
257
+ "pipeline",
258
+ "continuous integration",
259
+ "continuous deployment",
260
+ ],
261
+ Skill.DOCKER_SETUP: ["docker", "container", "dockerfile", "docker compose"],
262
+ Skill.KUBERNETES_SETUP: [
263
+ "kubernetes",
264
+ "k8s",
265
+ "deployment",
266
+ "pod",
267
+ "service",
268
+ ],
269
+ Skill.AZURE_DEPLOYMENT: ["azure", "cloud deployment", "azure devops"],
270
+ Skill.MONITORING_SETUP: [
271
+ "monitoring",
272
+ "observability",
273
+ "logging",
274
+ "metrics",
275
+ ],
276
+ Skill.DEPLOYMENT_STRATEGY: [
277
+ "deployment strategy",
278
+ "blue green",
279
+ "canary",
280
+ "rolling",
281
+ ],
282
+ Skill.INFRASTRUCTURE_AS_CODE: [
283
+ "infrastructure as code",
284
+ "iac",
285
+ "terraform",
286
+ "bicep",
287
+ ],
288
+ Skill.BACKUP_RECOVERY: ["backup", "disaster recovery", "dr"],
289
+ Skill.SCALING_STRATEGY: [
290
+ "scaling",
291
+ "auto scaling",
292
+ "horizontal scaling",
293
+ "vertical scaling",
294
+ ],
295
+ Skill.SECURITY_HARDENING: [
296
+ "security hardening",
297
+ "infrastructure security",
298
+ "network security",
299
+ ],
300
+ # Documentation skills
301
+ Skill.README_CREATION: ["readme", "read me", "project documentation"],
302
+ Skill.API_DOCUMENTATION: [
303
+ "api documentation",
304
+ "api doc",
305
+ "endpoint documentation",
306
+ ],
307
+ Skill.USER_GUIDE: ["user guide", "user manual", "how to"],
308
+ Skill.DEVELOPER_GUIDE: ["developer guide", "dev guide", "contributing"],
309
+ Skill.ARCHITECTURE_DOCUMENTATION: [
310
+ "architecture documentation",
311
+ "system documentation",
312
+ ],
313
+ Skill.CHANGELOG: ["changelog", "change log", "version history"],
314
+ Skill.TROUBLESHOOTING_GUIDE: ["troubleshooting", "faq", "help", "support"],
315
+ Skill.MIGRATION_GUIDE: ["migration guide", "upgrade guide", "migration"],
316
+ Skill.CODE_EXAMPLES: ["code example", "example", "sample code", "snippet"],
317
+ Skill.RELEASE_NOTES: ["release notes", "release note", "what's new"],
318
+ # Tool skills
319
+ Skill.WEB_SEARCH: ["search", "web search", "google", "find information"],
320
+ Skill.SQL_QUERY: [
321
+ "sql",
322
+ "query",
323
+ "database query",
324
+ "select",
325
+ "insert",
326
+ "update",
327
+ "delete",
328
+ ],
329
+ Skill.FILE_OPERATION: [
330
+ "file",
331
+ "read file",
332
+ "write file",
333
+ "create file",
334
+ "delete file",
335
+ ],
336
+ }
337
+
338
+ def detect_skills(self, task_description: str) -> Set[Skill]:
339
+ """Detect required skills from task description.
340
+
341
+ Args:
342
+ task_description: Description of the task
343
+
344
+ Returns:
345
+ Set of detected skills
346
+ """
347
+ task_lower = task_description.lower()
348
+ detected_skills = set()
349
+
350
+ for skill, patterns in self.skill_patterns.items():
351
+ for pattern in patterns:
352
+ if pattern.lower() in task_lower:
353
+ detected_skills.add(skill)
354
+ break
355
+
356
+ return detected_skills
357
+
358
+ def get_agent_for_skill(self, skill: Skill) -> Optional[str]:
359
+ """Get the agent name for a given skill.
360
+
361
+ Args:
362
+ skill: Skill to get agent for
363
+
364
+ Returns:
365
+ Agent name or None
366
+ """
367
+ skill_to_agent = {
368
+ # Product skills
369
+ Skill.REQUIREMENT_ANALYSIS: "product",
370
+ Skill.PRD_CREATION: "product",
371
+ Skill.USER_STORY_WRITING: "product",
372
+ Skill.PERSONA_CREATION: "product",
373
+ Skill.FEATURE_PRIORITIZATION: "product",
374
+ Skill.ACCEPTANCE_CRITERIA: "product",
375
+ # Architecture skills
376
+ Skill.SYSTEM_ARCHITECTURE: "architect",
377
+ Skill.TECH_STACK_SELECTION: "architect",
378
+ Skill.ADR_DOCUMENTATION: "architect",
379
+ Skill.API_DESIGN: "architect",
380
+ Skill.DATABASE_SCHEMA: "architect",
381
+ # UX skills
382
+ Skill.USER_FLOW_DESIGN: "ux",
383
+ Skill.WIREFRAME_CREATION: "ux",
384
+ Skill.DESIGN_SYSTEM: "ux",
385
+ Skill.ACCESSIBILITY: "ux",
386
+ Skill.PROTOTYPE_CREATION: "ux",
387
+ # Development skills
388
+ Skill.IMPLEMENTATION: "dev",
389
+ Skill.REFACTORING: "dev",
390
+ Skill.CODE_REVIEW: "dev",
391
+ Skill.TESTING: "dev",
392
+ Skill.DEBUGGING: "dev",
393
+ # Testing skills
394
+ Skill.TEST_STRATEGY: "test",
395
+ Skill.UNIT_TESTING: "test",
396
+ Skill.INTEGRATION_TESTING: "test",
397
+ Skill.E2E_TESTING: "test",
398
+ Skill.TEST_EXECUTION: "test",
399
+ Skill.PERFORMANCE_TESTING: "test",
400
+ Skill.SECURITY_TESTING: "test",
401
+ Skill.TEST_AUTOMATION: "test",
402
+ Skill.QUALITY_GATE: "test",
403
+ # Security skills
404
+ Skill.SECURITY_REVIEW: "security",
405
+ Skill.VULNERABILITY_SCAN: "security",
406
+ Skill.SECURE_CODING: "security",
407
+ Skill.DEPENDENCY_SECURITY: "security",
408
+ Skill.AUTHENTICATION_SECURITY: "security",
409
+ Skill.DATA_PROTECTION: "security",
410
+ Skill.API_SECURITY: "security",
411
+ Skill.SECURITY_MONITORING: "security",
412
+ Skill.COMPLIANCE_REVIEW: "security",
413
+ # DevOps skills
414
+ Skill.CI_CD_PIPELINE: "devops",
415
+ Skill.DOCKER_SETUP: "devops",
416
+ Skill.KUBERNETES_SETUP: "devops",
417
+ Skill.AZURE_DEPLOYMENT: "devops",
418
+ Skill.MONITORING_SETUP: "devops",
419
+ Skill.DEPLOYMENT_STRATEGY: "devops",
420
+ Skill.INFRASTRUCTURE_AS_CODE: "devops",
421
+ Skill.BACKUP_RECOVERY: "devops",
422
+ Skill.SCALING_STRATEGY: "devops",
423
+ Skill.SECURITY_HARDENING: "devops",
424
+ # Documentation skills
425
+ Skill.README_CREATION: "doc",
426
+ Skill.API_DOCUMENTATION: "doc",
427
+ Skill.USER_GUIDE: "doc",
428
+ Skill.DEVELOPER_GUIDE: "doc",
429
+ Skill.ARCHITECTURE_DOCUMENTATION: "doc",
430
+ Skill.CHANGELOG: "doc",
431
+ Skill.TROUBLESHOOTING_GUIDE: "doc",
432
+ Skill.MIGRATION_GUIDE: "doc",
433
+ Skill.CODE_EXAMPLES: "doc",
434
+ Skill.RELEASE_NOTES: "doc",
435
+ # Tool skills
436
+ Skill.WEB_SEARCH: "product",
437
+ Skill.SQL_QUERY: "architect",
438
+ Skill.FILE_OPERATION: "dev",
439
+ }
440
+
441
+ return skill_to_agent.get(skill)
442
+
443
+ async def execute_skills(
444
+ self, task_description: str, context: Optional[Dict[str, Any]] = None
445
+ ) -> Dict[str, Any]:
446
+ """Execute detected skills for a task.
447
+
448
+ Args:
449
+ task_description: Description of the task
450
+ context: Additional context
451
+
452
+ Returns:
453
+ Skill execution results
454
+ """
455
+ # Detect skills
456
+ skills = self.detect_skills(task_description)
457
+
458
+ if not skills:
459
+ return {
460
+ "status": "no_skills_detected",
461
+ "message": "No skills detected for the task",
462
+ }
463
+
464
+ print(f"🔍 Detected skills: {[s.value for s in skills]}")
465
+
466
+ # Group skills by agent
467
+ agent_skills: Dict[str, List[Skill]] = {}
468
+ for skill in skills:
469
+ agent = self.get_agent_for_skill(skill)
470
+ if agent:
471
+ if agent not in agent_skills:
472
+ agent_skills[agent] = []
473
+ agent_skills[agent].append(skill)
474
+
475
+ # Execute skills per agent
476
+ results = {}
477
+ for agent_name, agent_skills_list in agent_skills.items():
478
+ print(
479
+ f"🤖 Executing skills with {agent_name} agent: {[s.value for s in agent_skills_list]}"
480
+ )
481
+
482
+ # Create task description with skill context
483
+ skill_context = "\n".join(
484
+ [f"- {skill.value}: Execute this skill" for skill in agent_skills_list]
485
+ )
486
+
487
+ enhanced_task = f"""{task_description}
488
+
489
+ Required skills to execute:
490
+ {skill_context}
491
+
492
+ Execute all required skills and provide comprehensive results.
493
+ """
494
+
495
+ # Execute task with agent
496
+ result = await self.orchestrator.execute_task(enhanced_task, context)
497
+ results[agent_name] = result
498
+
499
+ # Log execution
500
+ self.skill_execution_history.append(
501
+ {
502
+ "task": task_description,
503
+ "skills": [s.value for s in agent_skills_list],
504
+ "agent": agent_name,
505
+ "result": result,
506
+ "timestamp": str(os.times()),
507
+ }
508
+ )
509
+
510
+ return {
511
+ "status": "success",
512
+ "detected_skills": [s.value for s in skills],
513
+ "agent_results": results,
514
+ }
515
+
516
+ def get_skill_execution_history(self) -> List[Dict[str, Any]]:
517
+ """Get skill execution history.
518
+
519
+ Returns:
520
+ List of skill execution records
521
+ """
522
+ return self.skill_execution_history
523
+
524
+ def clear_skill_execution_history(self):
525
+ """Clear skill execution history."""
526
+ self.skill_execution_history = []
527
+
528
+ def get_all_skills(self) -> List[str]:
529
+ """Get all available skills.
530
+
531
+ Returns:
532
+ List of skill names
533
+ """
534
+ return [skill.value for skill in Skill]
@@ -0,0 +1,11 @@
1
+ """CrewAI Tools Package"""
2
+
3
+ from .serper_tool import SerperTool
4
+ from .sql_tool import SQLTool
5
+ from .file_tool import FileTool
6
+
7
+ __all__ = [
8
+ "SerperTool",
9
+ "SQLTool",
10
+ "FileTool",
11
+ ]