empathy-framework 4.6.3__py3-none-any.whl → 4.6.5__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 (65) hide show
  1. {empathy_framework-4.6.3.dist-info → empathy_framework-4.6.5.dist-info}/METADATA +53 -11
  2. {empathy_framework-4.6.3.dist-info → empathy_framework-4.6.5.dist-info}/RECORD +32 -57
  3. empathy_llm_toolkit/agent_factory/crews/health_check.py +7 -4
  4. empathy_llm_toolkit/agent_factory/decorators.py +3 -2
  5. empathy_llm_toolkit/agent_factory/memory_integration.py +6 -2
  6. empathy_llm_toolkit/contextual_patterns.py +5 -2
  7. empathy_llm_toolkit/git_pattern_extractor.py +8 -4
  8. empathy_llm_toolkit/providers.py +4 -3
  9. empathy_os/__init__.py +1 -1
  10. empathy_os/cli/__init__.py +306 -0
  11. empathy_os/cli/__main__.py +26 -0
  12. empathy_os/cli/commands/__init__.py +8 -0
  13. empathy_os/cli/commands/inspection.py +48 -0
  14. empathy_os/cli/commands/memory.py +56 -0
  15. empathy_os/cli/commands/provider.py +86 -0
  16. empathy_os/cli/commands/utilities.py +94 -0
  17. empathy_os/cli/core.py +32 -0
  18. empathy_os/cli.py +18 -6
  19. empathy_os/cli_unified.py +19 -3
  20. empathy_os/memory/short_term.py +12 -2
  21. empathy_os/project_index/scanner.py +151 -49
  22. empathy_os/socratic/visual_editor.py +9 -4
  23. empathy_os/workflows/bug_predict.py +70 -1
  24. empathy_os/workflows/pr_review.py +6 -0
  25. empathy_os/workflows/security_audit.py +13 -0
  26. empathy_os/workflows/tier_tracking.py +50 -2
  27. wizards/discharge_summary_wizard.py +4 -2
  28. wizards/incident_report_wizard.py +4 -2
  29. empathy_os/meta_workflows/agent_creator 2.py +0 -254
  30. empathy_os/meta_workflows/builtin_templates 2.py +0 -567
  31. empathy_os/meta_workflows/cli_meta_workflows 2.py +0 -1551
  32. empathy_os/meta_workflows/form_engine 2.py +0 -304
  33. empathy_os/meta_workflows/intent_detector 2.py +0 -298
  34. empathy_os/meta_workflows/pattern_learner 2.py +0 -754
  35. empathy_os/meta_workflows/session_context 2.py +0 -398
  36. empathy_os/meta_workflows/template_registry 2.py +0 -229
  37. empathy_os/meta_workflows/workflow 2.py +0 -980
  38. empathy_os/orchestration/pattern_learner 2.py +0 -699
  39. empathy_os/orchestration/real_tools 2.py +0 -938
  40. empathy_os/socratic/__init__ 2.py +0 -273
  41. empathy_os/socratic/ab_testing 2.py +0 -969
  42. empathy_os/socratic/blueprint 2.py +0 -532
  43. empathy_os/socratic/cli 2.py +0 -689
  44. empathy_os/socratic/collaboration 2.py +0 -1112
  45. empathy_os/socratic/domain_templates 2.py +0 -916
  46. empathy_os/socratic/embeddings 2.py +0 -734
  47. empathy_os/socratic/engine 2.py +0 -729
  48. empathy_os/socratic/explainer 2.py +0 -663
  49. empathy_os/socratic/feedback 2.py +0 -767
  50. empathy_os/socratic/forms 2.py +0 -624
  51. empathy_os/socratic/generator 2.py +0 -716
  52. empathy_os/socratic/llm_analyzer 2.py +0 -635
  53. empathy_os/socratic/mcp_server 2.py +0 -751
  54. empathy_os/socratic/session 2.py +0 -306
  55. empathy_os/socratic/storage 2.py +0 -635
  56. empathy_os/socratic/success 2.py +0 -719
  57. empathy_os/socratic/visual_editor 2.py +0 -812
  58. empathy_os/socratic/web_ui 2.py +0 -925
  59. empathy_os/workflows/batch_processing 2.py +0 -310
  60. empathy_os/workflows/release_prep_crew 2.py +0 -968
  61. empathy_os/workflows/test_coverage_boost_crew 2.py +0 -848
  62. {empathy_framework-4.6.3.dist-info → empathy_framework-4.6.5.dist-info}/WHEEL +0 -0
  63. {empathy_framework-4.6.3.dist-info → empathy_framework-4.6.5.dist-info}/entry_points.txt +0 -0
  64. {empathy_framework-4.6.3.dist-info → empathy_framework-4.6.5.dist-info}/licenses/LICENSE +0 -0
  65. {empathy_framework-4.6.3.dist-info → empathy_framework-4.6.5.dist-info}/top_level.txt +0 -0
@@ -1,968 +0,0 @@
1
- """Release Preparation Crew - Multi-Agent Workflow
2
-
3
- .. deprecated:: 4.3.0
4
- This workflow is deprecated in favor of the meta-workflow system.
5
- Use ``empathy meta-workflow run release-prep`` instead.
6
- See docs/CREWAI_MIGRATION.md for migration guide.
7
-
8
- Comprehensive release readiness assessment using a multi-agent crew.
9
-
10
- Pattern: Crew
11
- - Multiple specialized AI agents collaborate on the task
12
- - Process Type: parallel (agents run simultaneously)
13
- - Agents: 4
14
-
15
- Agents:
16
- - Security Agent: Vulnerability scanning and security audit
17
- - Testing Agent: Test coverage analysis and quality validation
18
- - Quality Agent: Code quality review and best practices check
19
- - Documentation Agent: Documentation completeness verification
20
-
21
- Copyright 2025 Smart-AI-Memory
22
- Licensed under Fair Source License 0.9
23
- """
24
- import asyncio
25
- import os
26
- import warnings
27
- from dataclasses import dataclass, field
28
- from datetime import datetime
29
- from typing import Any
30
-
31
- # Try to import the LLM executor for actual AI calls
32
- EmpathyLLMExecutor = None
33
- ExecutionContext = None
34
- HAS_EXECUTOR = False
35
-
36
- try:
37
- from empathy_os.models import ExecutionContext as _ExecutionContext
38
- from empathy_os.models.empathy_executor import EmpathyLLMExecutor as _EmpathyLLMExecutor
39
-
40
- EmpathyLLMExecutor = _EmpathyLLMExecutor
41
- ExecutionContext = _ExecutionContext
42
- HAS_EXECUTOR = True
43
- except ImportError:
44
- pass
45
-
46
- # Try to import the ProjectIndex for file tracking
47
- ProjectIndex = None
48
- HAS_PROJECT_INDEX = False
49
-
50
- try:
51
- from empathy_os.project_index import ProjectIndex as _ProjectIndex
52
-
53
- ProjectIndex = _ProjectIndex
54
- HAS_PROJECT_INDEX = True
55
- except ImportError:
56
- pass
57
-
58
-
59
- @dataclass
60
- class QualityGate:
61
- """Quality gate threshold for release readiness."""
62
-
63
- name: str
64
- threshold: float
65
- actual: float = 0.0
66
- passed: bool = False
67
- critical: bool = True
68
- message: str = ""
69
-
70
- def __post_init__(self):
71
- """Generate message if not provided."""
72
- if not self.message:
73
- status = "✅ PASS" if self.passed else "❌ FAIL"
74
- self.message = (
75
- f"{self.name}: {status} "
76
- f"(actual: {self.actual:.1f}, threshold: {self.threshold:.1f})"
77
- )
78
-
79
-
80
- @dataclass
81
- class ReleasePreparationCrewResult:
82
- """Result from ReleasePreparationCrew execution."""
83
-
84
- success: bool
85
- approved: bool # Overall release approval
86
- confidence: str # "high", "medium", "low"
87
-
88
- # Quality gates
89
- quality_gates: list[QualityGate] = field(default_factory=list)
90
-
91
- # Agent findings
92
- security_findings: dict = field(default_factory=dict)
93
- testing_findings: dict = field(default_factory=dict)
94
- quality_findings: dict = field(default_factory=dict)
95
- documentation_findings: dict = field(default_factory=dict)
96
-
97
- # Aggregate metrics
98
- blockers: list[str] = field(default_factory=list)
99
- warnings: list[str] = field(default_factory=list)
100
- recommendations: list[str] = field(default_factory=list)
101
-
102
- # Cost tracking
103
- cost: float = 0.0
104
- duration_ms: int = 0
105
- timestamp: str = field(default_factory=lambda: datetime.now().isoformat())
106
-
107
- def to_dict(self) -> dict:
108
- """Convert result to dictionary."""
109
- return {
110
- "success": self.success,
111
- "approved": self.approved,
112
- "confidence": self.confidence,
113
- "quality_gates": [
114
- {
115
- "name": gate.name,
116
- "threshold": gate.threshold,
117
- "actual": gate.actual,
118
- "passed": gate.passed,
119
- "critical": gate.critical,
120
- "message": gate.message,
121
- }
122
- for gate in self.quality_gates
123
- ],
124
- "security_findings": self.security_findings,
125
- "testing_findings": self.testing_findings,
126
- "quality_findings": self.quality_findings,
127
- "documentation_findings": self.documentation_findings,
128
- "blockers": self.blockers,
129
- "warnings": self.warnings,
130
- "recommendations": self.recommendations,
131
- "cost": self.cost,
132
- "duration_ms": self.duration_ms,
133
- "timestamp": self.timestamp,
134
- }
135
-
136
- @property
137
- def formatted_report(self) -> str:
138
- """Generate human-readable formatted report."""
139
- return format_release_prep_report(self)
140
-
141
-
142
- @dataclass
143
- class Agent:
144
- """Agent configuration for the crew with XML-enhanced prompting."""
145
-
146
- role: str
147
- goal: str
148
- backstory: str
149
- expertise_level: str = "expert"
150
- use_xml_structure: bool = True
151
-
152
- def get_system_prompt(self) -> str:
153
- """Generate XML-enhanced system prompt for this agent."""
154
- return f"""<agent_role>
155
- You are a {self.role} with {self.expertise_level}-level expertise.
156
- </agent_role>
157
-
158
- <agent_goal>
159
- {self.goal}
160
- </agent_goal>
161
-
162
- <agent_backstory>
163
- {self.backstory}
164
- </agent_backstory>
165
-
166
- <instructions>
167
- 1. Carefully review all provided context data
168
- 2. Think through your analysis step-by-step
169
- 3. Provide thorough, actionable analysis
170
- 4. Be specific and cite file paths when relevant
171
- 5. Structure your output according to the requested format
172
- </instructions>
173
-
174
- <output_structure>
175
- Always structure your response as:
176
-
177
- <thinking>
178
- [Your step-by-step reasoning process]
179
- - What you observe in the context
180
- - How you analyze the situation
181
- - What conclusions you draw
182
- </thinking>
183
-
184
- <answer>
185
- [Your final output in the requested format]
186
- </answer>
187
- </output_structure>"""
188
-
189
-
190
- @dataclass
191
- class Task:
192
- """Task configuration for the crew with XML-enhanced prompting."""
193
-
194
- description: str
195
- expected_output: str
196
- agent: Agent
197
-
198
- def get_user_prompt(self, context: dict) -> str:
199
- """Generate XML-enhanced user prompt for this task with context."""
200
- # Build structured context with proper XML tags
201
- context_sections = []
202
- for key, value in context.items():
203
- if value:
204
- # Use underscores for tag names
205
- tag_name = key.replace(" ", "_").replace("-", "_").lower()
206
- # Wrap in appropriate tags
207
- context_sections.append(f"<{tag_name}>\n{value}\n</{tag_name}>")
208
-
209
- context_xml = "\n".join(context_sections)
210
-
211
- return f"""<task_description>
212
- {self.description}
213
- </task_description>
214
-
215
- <context>
216
- {context_xml}
217
- </context>
218
-
219
- <expected_output>
220
- {self.expected_output}
221
- </expected_output>
222
-
223
- <instructions>
224
- 1. Review all context data in the <context> tags above
225
- 2. Structure your response using <thinking> and <answer> tags as defined in your system prompt
226
- 3. Match the expected output format exactly
227
- 4. Be thorough and specific in your analysis
228
- </instructions>"""
229
-
230
-
231
- def parse_xml_response(response: str) -> dict:
232
- """Parse XML-structured agent response.
233
-
234
- Args:
235
- response: Raw agent response potentially containing XML tags
236
-
237
- Returns:
238
- Dict with 'thinking' and 'answer' sections (if found) or raw response
239
- """
240
- result = {
241
- "thinking": "",
242
- "answer": "",
243
- "raw": response,
244
- "has_xml_structure": False,
245
- }
246
-
247
- # Try to extract thinking section
248
- thinking_start = response.find("<thinking>")
249
- thinking_end = response.find("</thinking>")
250
- if thinking_start != -1 and thinking_end != -1:
251
- result["thinking"] = response[thinking_start + 10 : thinking_end].strip()
252
- result["has_xml_structure"] = True
253
-
254
- # Try to extract answer section
255
- answer_start = response.find("<answer>")
256
- answer_end = response.find("</answer>")
257
- if answer_start != -1 and answer_end != -1:
258
- result["answer"] = response[answer_start + 8 : answer_end].strip()
259
- result["has_xml_structure"] = True
260
-
261
- # If no XML structure found, use full response as answer
262
- if not result["has_xml_structure"]:
263
- result["answer"] = response
264
-
265
- return result
266
-
267
-
268
- def format_release_prep_report(result: ReleasePreparationCrewResult) -> str:
269
- """Format release preparation result as human-readable text."""
270
- lines = []
271
-
272
- # Header
273
- lines.append("=" * 70)
274
- lines.append("RELEASE READINESS REPORT (CrewAI Multi-Agent)")
275
- lines.append("=" * 70)
276
- lines.append("")
277
-
278
- # Status
279
- status_icon = "✅" if result.approved else "❌"
280
- status_text = "APPROVED FOR RELEASE" if result.approved else "NOT READY FOR RELEASE"
281
- lines.append(f"Status: {status_icon} {status_text}")
282
- lines.append(f"Confidence: {result.confidence.upper()}")
283
- lines.append(f"Generated: {result.timestamp}")
284
- lines.append(f"Duration: {result.duration_ms}ms ({result.duration_ms / 1000:.1f}s)")
285
- lines.append(f"Cost: ${result.cost:.4f}")
286
- lines.append("")
287
-
288
- # Quality Gates
289
- if result.quality_gates:
290
- lines.append("-" * 70)
291
- lines.append("QUALITY GATES")
292
- lines.append("-" * 70)
293
- for gate in result.quality_gates:
294
- icon = "✅" if gate.passed else ("🔴" if gate.critical else "⚠️")
295
- lines.append(f"{icon} {gate.message}")
296
- lines.append("")
297
-
298
- # Blockers
299
- if result.blockers:
300
- lines.append("-" * 70)
301
- lines.append("🚫 RELEASE BLOCKERS")
302
- lines.append("-" * 70)
303
- for blocker in result.blockers:
304
- lines.append(f" • {blocker}")
305
- lines.append("")
306
-
307
- # Warnings
308
- if result.warnings:
309
- lines.append("-" * 70)
310
- lines.append("⚠️ WARNINGS")
311
- lines.append("-" * 70)
312
- for warning in result.warnings:
313
- lines.append(f" • {warning}")
314
- lines.append("")
315
-
316
- # Recommendations
317
- if result.recommendations:
318
- lines.append("-" * 70)
319
- lines.append("💡 RECOMMENDATIONS")
320
- lines.append("-" * 70)
321
- for i, rec in enumerate(result.recommendations, 1):
322
- lines.append(f"{i}. {rec}")
323
- lines.append("")
324
-
325
- # Agent Findings Summary
326
- lines.append("-" * 70)
327
- lines.append("AGENT FINDINGS")
328
- lines.append("-" * 70)
329
-
330
- if result.security_findings:
331
- lines.append("\n🔒 Security Agent:")
332
- lines.append(f" {result.security_findings.get('summary', 'No summary available')}")
333
-
334
- if result.testing_findings:
335
- lines.append("\n🧪 Testing Agent:")
336
- lines.append(f" {result.testing_findings.get('summary', 'No summary available')}")
337
-
338
- if result.quality_findings:
339
- lines.append("\n⚡ Quality Agent:")
340
- lines.append(f" {result.quality_findings.get('summary', 'No summary available')}")
341
-
342
- if result.documentation_findings:
343
- lines.append("\n📝 Documentation Agent:")
344
- lines.append(f" {result.documentation_findings.get('summary', 'No summary available')}")
345
-
346
- lines.append("")
347
-
348
- # Footer
349
- lines.append("=" * 70)
350
- if result.approved:
351
- lines.append("✅ Release preparation complete - ready to ship")
352
- else:
353
- lines.append("❌ Release blocked - address issues above before shipping")
354
- lines.append("=" * 70)
355
-
356
- return "\n".join(lines)
357
-
358
-
359
- class ReleasePreparationCrew:
360
- """Release Preparation Crew - Multi-agent release readiness assessment.
361
-
362
- Uses 4 specialized agents running in parallel to comprehensively
363
- evaluate release readiness across security, testing, quality, and documentation.
364
-
365
- Process Type: parallel
366
-
367
- Agents:
368
- - Security Agent: Vulnerability scanning and security audit
369
- - Testing Agent: Test coverage analysis and quality validation
370
- - Quality Agent: Code quality review and best practices check
371
- - Documentation Agent: Documentation completeness verification
372
-
373
- Usage:
374
- crew = ReleasePreparationCrew()
375
- result = await crew.execute(path="./src")
376
-
377
- if result.approved:
378
- print("✅ Ready for release!")
379
- else:
380
- for blocker in result.blockers:
381
- print(f"BLOCKER: {blocker}")
382
- """
383
-
384
- name = "Release_Preparation_Crew"
385
- description = "Comprehensive release readiness assessment using multi-agent crew"
386
- process_type = "parallel"
387
-
388
- def __init__(
389
- self, project_root: str = ".", quality_gates: dict[str, float] | None = None, **kwargs: Any
390
- ):
391
- """Initialize the crew with configured agents.
392
-
393
- .. deprecated:: 4.3.0
394
- Use meta-workflow system instead: ``empathy meta-workflow run release-prep``
395
-
396
- Args:
397
- project_root: Root directory of project to analyze
398
- quality_gates: Optional quality gate thresholds
399
- - security: 0 critical issues (default)
400
- - coverage: 80% test coverage (default)
401
- - quality: 7.0 quality score (default)
402
- - documentation: 100% doc coverage (default)
403
- **kwargs: Additional configuration
404
- """
405
- warnings.warn(
406
- "ReleasePreparationCrew is deprecated since v4.3.0. "
407
- "Use meta-workflow system instead: empathy meta-workflow run release-prep. "
408
- "See docs/CREWAI_MIGRATION.md for migration guide.",
409
- DeprecationWarning,
410
- stacklevel=2,
411
- )
412
- self.config = kwargs
413
- self.project_root = project_root
414
- self._executor = None
415
- self._project_index = None
416
- self._total_cost = 0.0
417
- self._total_input_tokens = 0
418
- self._total_output_tokens = 0
419
-
420
- # Set default quality gates
421
- self.quality_gates = {
422
- "security": 0.0, # No critical issues
423
- "coverage": 80.0, # 80% test coverage
424
- "quality": 7.0, # Quality score ≥ 7
425
- "documentation": 100.0, # 100% doc coverage
426
- }
427
- if quality_gates:
428
- self.quality_gates.update(quality_gates)
429
-
430
- # Initialize executor if available
431
- if HAS_EXECUTOR and EmpathyLLMExecutor is not None:
432
- api_key = os.getenv("ANTHROPIC_API_KEY")
433
- if api_key:
434
- try:
435
- self._executor = EmpathyLLMExecutor(
436
- provider="anthropic",
437
- api_key=api_key,
438
- )
439
- except Exception:
440
- pass
441
-
442
- # Initialize ProjectIndex if available
443
- if HAS_PROJECT_INDEX and ProjectIndex is not None:
444
- try:
445
- self._project_index = ProjectIndex(project_root)
446
- if not self._project_index.load():
447
- # Index doesn't exist or is stale, refresh it
448
- print(" [ProjectIndex] Building index (first run)...")
449
- self._project_index.refresh()
450
- except Exception as e:
451
- print(f" [ProjectIndex] Warning: Could not load index: {e}")
452
-
453
- # Define agents
454
- self.security_agent = Agent(
455
- role="Security Auditor",
456
- goal="Perform comprehensive security audit and vulnerability scan",
457
- backstory="Expert security auditor specializing in OWASP Top 10 vulnerabilities, dependency security, and security best practices. Skilled at identifying critical security issues that would block release.",
458
- expertise_level="expert",
459
- )
460
-
461
- self.testing_agent = Agent(
462
- role="Test Coverage Analyst",
463
- goal="Analyze test coverage and validate testing quality",
464
- backstory="Testing expert focused on test coverage metrics, test quality, and identifying critical gaps. Ensures adequate testing before release.",
465
- expertise_level="expert",
466
- )
467
-
468
- self.quality_agent = Agent(
469
- role="Code Quality Reviewer",
470
- goal="Review code quality and adherence to best practices",
471
- backstory="Senior code reviewer focused on code maintainability, complexity, and best practices. Identifies code quality issues that impact long-term project health.",
472
- expertise_level="expert",
473
- )
474
-
475
- self.documentation_agent = Agent(
476
- role="Documentation Specialist",
477
- goal="Verify documentation completeness and accuracy",
478
- backstory="Technical writer and documentation expert. Ensures all code is properly documented, README is up-to-date, and API docs are complete.",
479
- expertise_level="expert",
480
- )
481
-
482
- # Store all agents
483
- self.agents = [
484
- self.security_agent,
485
- self.testing_agent,
486
- self.quality_agent,
487
- self.documentation_agent,
488
- ]
489
-
490
- def define_tasks(self) -> list[Task]:
491
- """Define the tasks for this crew."""
492
- return [
493
- Task(
494
- description=f"Perform security audit: 1) Scan for OWASP Top 10 vulnerabilities, 2) Check dependency security, 3) Review authentication/authorization, 4) Identify critical security issues. Quality gate: ≤{self.quality_gates['security']} critical issues",
495
- expected_output="JSON with: critical_issues_count, high_issues_count, findings (list of issues with severity/details), recommendation (GO/NO_GO)",
496
- agent=self.security_agent,
497
- ),
498
- Task(
499
- description=f"Analyze test coverage: 1) Calculate current test coverage percentage, 2) Identify critical gaps in coverage, 3) Assess test quality, 4) Verify tests pass. Quality gate: ≥{self.quality_gates['coverage']}% coverage",
500
- expected_output="JSON with: coverage_percentage, critical_gaps_count, tests_passing (true/false), recommendation (GO/NO_GO)",
501
- agent=self.testing_agent,
502
- ),
503
- Task(
504
- description=f"Review code quality: 1) Calculate code quality score (0-10), 2) Check for code smells and anti-patterns, 3) Verify linting passes, 4) Assess maintainability. Quality gate: ≥{self.quality_gates['quality']} quality score",
505
- expected_output="JSON with: quality_score, complexity_issues, linting_errors, recommendation (GO/NO_GO)",
506
- agent=self.quality_agent,
507
- ),
508
- Task(
509
- description=f"Verify documentation: 1) Check docstring coverage, 2) Verify README is current, 3) Validate API documentation, 4) Check for missing docs. Quality gate: ≥{self.quality_gates['documentation']}% doc coverage",
510
- expected_output="JSON with: docstring_coverage_percentage, readme_current (true/false), missing_docs_count, recommendation (GO/NO_GO)",
511
- agent=self.documentation_agent,
512
- ),
513
- ]
514
-
515
- async def _call_llm(
516
- self,
517
- agent: Agent,
518
- task: Task,
519
- context: dict,
520
- task_type: str = "release_validation",
521
- ) -> tuple[str, int, int, float]:
522
- """Call the LLM with agent/task configuration.
523
-
524
- Returns: (response_text, input_tokens, output_tokens, cost)
525
- """
526
- system_prompt = agent.get_system_prompt()
527
- user_prompt = task.get_user_prompt(context)
528
-
529
- if self._executor is None:
530
- # Fallback: return mock response
531
- return await self._mock_llm_call(agent, task)
532
-
533
- try:
534
- # Create execution context
535
- exec_context = ExecutionContext(
536
- task_type=task_type,
537
- workflow_name="release-prep",
538
- step_name=agent.role,
539
- )
540
-
541
- # Execute with timeout using correct LLMExecutor API
542
- result = await asyncio.wait_for(
543
- self._executor.run(
544
- task_type=task_type,
545
- prompt=user_prompt,
546
- system=system_prompt,
547
- context=exec_context,
548
- ),
549
- timeout=120.0, # 2 minute timeout
550
- )
551
-
552
- response = result.content
553
- input_tokens = result.input_tokens
554
- output_tokens = result.output_tokens
555
- cost = result.cost
556
-
557
- # Track totals
558
- self._total_cost += cost
559
- self._total_input_tokens += input_tokens
560
- self._total_output_tokens += output_tokens
561
-
562
- return (response, input_tokens, output_tokens, cost)
563
-
564
- except asyncio.TimeoutError:
565
- print(f" [LLM] Timeout calling {agent.role}")
566
- return await self._mock_llm_call(agent, task, reason="Timeout")
567
- except Exception as e:
568
- print(f" [LLM] Error calling {agent.role}: {e}")
569
- return await self._mock_llm_call(agent, task, reason=str(e))
570
-
571
- async def _mock_llm_call(
572
- self, agent: Agent, task: Task, reason: str = "No API key"
573
- ) -> tuple[str, int, int, float]:
574
- """Generate mock response when LLM is unavailable."""
575
- # Simulate brief delay
576
- await asyncio.sleep(0.1)
577
-
578
- mock_findings = {
579
- "Security Auditor": f"""[Mock Security Audit - {reason}]
580
-
581
- <thinking>
582
- Performing security audit of the codebase...
583
- - Scanning for OWASP Top 10 vulnerabilities
584
- - Checking dependency versions
585
- - Reviewing authentication mechanisms
586
- </thinking>
587
-
588
- <answer>
589
- {{
590
- "critical_issues_count": 0,
591
- "high_issues_count": 2,
592
- "findings": [
593
- {{"severity": "high", "details": "Outdated dependency: requests 2.25.0 (CVE-2024-XXXX)"}},
594
- {{"severity": "medium", "details": "Missing rate limiting on API endpoints"}}
595
- ],
596
- "recommendation": "GO (no critical blockers, address high issues post-release)"
597
- }}
598
- </answer>
599
-
600
- Note: This is a mock response. Configure ANTHROPIC_API_KEY for real analysis.""",
601
- "Test Coverage Analyst": f"""[Mock Coverage Analysis - {reason}]
602
-
603
- <thinking>
604
- Analyzing test coverage across the codebase...
605
- - Running coverage tools
606
- - Identifying critical gaps
607
- - Verifying tests pass
608
- </thinking>
609
-
610
- <answer>
611
- {{
612
- "coverage_percentage": 75.5,
613
- "critical_gaps_count": 3,
614
- "tests_passing": true,
615
- "recommendation": "NO_GO (coverage below 80% threshold)"
616
- }}
617
- </answer>
618
-
619
- Note: This is a mock response. Configure ANTHROPIC_API_KEY for real analysis.""",
620
- "Code Quality Reviewer": f"""[Mock Quality Review - {reason}]
621
-
622
- <thinking>
623
- Reviewing code quality metrics...
624
- - Calculating complexity scores
625
- - Checking linting status
626
- - Assessing maintainability
627
- </thinking>
628
-
629
- <answer>
630
- {{
631
- "quality_score": 8.2,
632
- "complexity_issues": 2,
633
- "linting_errors": 0,
634
- "recommendation": "GO (quality score above threshold)"
635
- }}
636
- </answer>
637
-
638
- Note: This is a mock response. Configure ANTHROPIC_API_KEY for real analysis.""",
639
- "Documentation Specialist": f"""[Mock Documentation Check - {reason}]
640
-
641
- <thinking>
642
- Verifying documentation completeness...
643
- - Checking docstring coverage
644
- - Reviewing README currency
645
- - Validating API docs
646
- </thinking>
647
-
648
- <answer>
649
- {{
650
- "docstring_coverage_percentage": 92.0,
651
- "readme_current": false,
652
- "missing_docs_count": 5,
653
- "recommendation": "CONDITIONAL (README needs update)"
654
- }}
655
- </answer>
656
-
657
- Note: This is a mock response. Configure ANTHROPIC_API_KEY for real analysis.""",
658
- }
659
-
660
- response = mock_findings.get(agent.role, f"Mock response for {agent.role}")
661
- return (response, 0, 0, 0.0)
662
-
663
- def _get_index_context(self) -> dict[str, Any]:
664
- """Get release validation context from ProjectIndex if available."""
665
- if self._project_index is None:
666
- return {}
667
-
668
- try:
669
- return self._project_index.get_context_for_workflow("release_prep")
670
- except Exception as e:
671
- print(f" [ProjectIndex] Warning: Could not get context: {e}")
672
- return {}
673
-
674
- async def execute(
675
- self,
676
- path: str = ".",
677
- context: dict | None = None,
678
- **kwargs: Any,
679
- ) -> ReleasePreparationCrewResult:
680
- """Execute the release preparation crew.
681
-
682
- Args:
683
- path: Path to analyze for release readiness
684
- context: Additional context for agents
685
- **kwargs: Additional arguments
686
-
687
- Returns:
688
- ReleasePreparationCrewResult with approval status and findings
689
- """
690
- started_at = datetime.now()
691
- context = context or {}
692
-
693
- print("\n" + "=" * 70)
694
- print(" RELEASE PREPARATION CREW (CrewAI)")
695
- print("=" * 70)
696
- print(f"\n Project Path: {path}")
697
- print(f" Agents: {len(self.agents)} (running in parallel)")
698
- print("")
699
-
700
- # Try to get rich context from ProjectIndex
701
- index_context = self._get_index_context()
702
-
703
- if index_context:
704
- print(" [ProjectIndex] Using indexed project data")
705
- agent_context = {
706
- "path": path,
707
- **index_context,
708
- **context,
709
- }
710
- else:
711
- # Fallback: basic context
712
- agent_context = {
713
- "path": path,
714
- "quality_gates": self.quality_gates,
715
- **context,
716
- }
717
-
718
- # Define tasks
719
- tasks = self.define_tasks()
720
-
721
- # Execute all agents in parallel
722
- print(" 🚀 Executing agents in parallel...\n")
723
-
724
- agent_tasks = []
725
- for agent, task in zip(self.agents, tasks, strict=False):
726
- print(f" • {agent.role}")
727
- agent_tasks.append(self._call_llm(agent, task, agent_context))
728
-
729
- # Wait for all agents to complete
730
- results = await asyncio.gather(*agent_tasks)
731
-
732
- print("\n ✓ All agents completed\n")
733
-
734
- # Parse agent responses
735
- agent_findings = []
736
- for agent, _, (response, input_tokens, output_tokens, cost) in zip(
737
- self.agents, tasks, results, strict=False
738
- ):
739
- parsed = parse_xml_response(response)
740
- agent_findings.append(
741
- {
742
- "agent": agent.role,
743
- "response": response,
744
- "thinking": parsed["thinking"],
745
- "answer": parsed["answer"],
746
- "has_xml_structure": parsed["has_xml_structure"],
747
- "cost": cost,
748
- "input_tokens": input_tokens,
749
- "output_tokens": output_tokens,
750
- }
751
- )
752
-
753
- # Extract structured findings from each agent
754
- security_findings = self._extract_security_findings(agent_findings[0])
755
- testing_findings = self._extract_testing_findings(agent_findings[1])
756
- quality_findings = self._extract_quality_findings(agent_findings[2])
757
- documentation_findings = self._extract_documentation_findings(agent_findings[3])
758
-
759
- # Evaluate quality gates
760
- quality_gates = self._evaluate_quality_gates(
761
- security_findings, testing_findings, quality_findings, documentation_findings
762
- )
763
-
764
- # Determine approval status
765
- blockers = []
766
- warnings = []
767
- recommendations = []
768
-
769
- for gate in quality_gates:
770
- if not gate.passed:
771
- if gate.critical:
772
- blockers.append(f"{gate.name} failed: {gate.message}")
773
- else:
774
- warnings.append(f"{gate.name} below threshold: {gate.message}")
775
-
776
- approved = len(blockers) == 0
777
- confidence = (
778
- "high" if approved and len(warnings) == 0 else ("medium" if approved else "low")
779
- )
780
-
781
- # Calculate duration
782
- duration_ms = int((datetime.now() - started_at).total_seconds() * 1000)
783
-
784
- # Build result
785
- result = ReleasePreparationCrewResult(
786
- success=True,
787
- approved=approved,
788
- confidence=confidence,
789
- quality_gates=quality_gates,
790
- security_findings=security_findings,
791
- testing_findings=testing_findings,
792
- quality_findings=quality_findings,
793
- documentation_findings=documentation_findings,
794
- blockers=blockers,
795
- warnings=warnings,
796
- recommendations=recommendations,
797
- cost=self._total_cost,
798
- duration_ms=duration_ms,
799
- )
800
-
801
- # Add formatted report
802
- print(result.formatted_report)
803
-
804
- return result
805
-
806
- def _parse_json_answer(self, answer: str) -> dict | None:
807
- """Parse JSON from agent answer, handling markdown code blocks.
808
-
809
- Args:
810
- answer: Agent answer text (may contain ```json...```)
811
-
812
- Returns:
813
- Parsed JSON dict or None if parsing fails
814
- """
815
- import json
816
- import re
817
-
818
- try:
819
- # Remove markdown code blocks if present
820
- answer_cleaned = re.sub(r"```json\s*", "", answer)
821
- answer_cleaned = re.sub(r"```\s*$", "", answer_cleaned)
822
- answer_cleaned = answer_cleaned.strip()
823
-
824
- # Parse as JSON
825
- return json.loads(answer_cleaned)
826
- except Exception:
827
- return None
828
-
829
- def _extract_security_findings(self, agent_finding: dict) -> dict:
830
- """Extract structured security findings from agent response."""
831
- answer = agent_finding.get("answer", "")
832
- data = self._parse_json_answer(answer)
833
-
834
- if data:
835
- return {
836
- "critical_count": data.get("critical_issues_count", 0),
837
- "high_count": data.get("high_issues_count", 0),
838
- "findings": data.get("findings", []),
839
- "recommendation": data.get("recommendation", "UNKNOWN"),
840
- "summary": f"{data.get('critical_issues_count', 0)} critical, {data.get('high_issues_count', 0)} high issues found",
841
- }
842
-
843
- # Fallback
844
- return {
845
- "critical_count": 0,
846
- "high_count": 0,
847
- "findings": [],
848
- "recommendation": "UNKNOWN",
849
- "summary": "Could not parse security findings",
850
- }
851
-
852
- def _extract_testing_findings(self, agent_finding: dict) -> dict:
853
- """Extract structured testing findings from agent response."""
854
- answer = agent_finding.get("answer", "")
855
- data = self._parse_json_answer(answer)
856
-
857
- if data:
858
- return {
859
- "coverage": data.get("coverage_percentage", 0.0),
860
- "gaps_count": data.get("critical_gaps_count", 0),
861
- "tests_passing": data.get("tests_passing", False),
862
- "recommendation": data.get("recommendation", "UNKNOWN"),
863
- "summary": f"{data.get('coverage_percentage', 0)}% coverage, {data.get('critical_gaps_count', 0)} critical gaps",
864
- }
865
-
866
- return {
867
- "coverage": 0.0,
868
- "gaps_count": 0,
869
- "tests_passing": False,
870
- "recommendation": "UNKNOWN",
871
- "summary": "Could not parse testing findings",
872
- }
873
-
874
- def _extract_quality_findings(self, agent_finding: dict) -> dict:
875
- """Extract structured quality findings from agent response."""
876
- answer = agent_finding.get("answer", "")
877
- data = self._parse_json_answer(answer)
878
-
879
- if data:
880
- return {
881
- "quality_score": data.get("quality_score", 0.0),
882
- "complexity_issues": data.get("complexity_issues", 0),
883
- "linting_errors": data.get("linting_errors", 0),
884
- "recommendation": data.get("recommendation", "UNKNOWN"),
885
- "summary": f"Quality score: {data.get('quality_score', 0)}/10, {data.get('complexity_issues', 0)} complexity issues",
886
- }
887
-
888
- return {
889
- "quality_score": 0.0,
890
- "complexity_issues": 0,
891
- "linting_errors": 0,
892
- "recommendation": "UNKNOWN",
893
- "summary": "Could not parse quality findings",
894
- }
895
-
896
- def _extract_documentation_findings(self, agent_finding: dict) -> dict:
897
- """Extract structured documentation findings from agent response."""
898
- answer = agent_finding.get("answer", "")
899
- data = self._parse_json_answer(answer)
900
-
901
- if data:
902
- return {
903
- "docstring_coverage": data.get("docstring_coverage_percentage", 0.0),
904
- "readme_current": data.get("readme_current", False),
905
- "missing_docs_count": data.get("missing_docs_count", 0),
906
- "recommendation": data.get("recommendation", "UNKNOWN"),
907
- "summary": f"{data.get('docstring_coverage_percentage', 0)}% docstring coverage, README {'current' if data.get('readme_current') else 'needs update'}",
908
- }
909
-
910
- return {
911
- "docstring_coverage": 0.0,
912
- "readme_current": False,
913
- "missing_docs_count": 0,
914
- "recommendation": "UNKNOWN",
915
- "summary": "Could not parse documentation findings",
916
- }
917
-
918
- def _evaluate_quality_gates(
919
- self,
920
- security_findings: dict,
921
- testing_findings: dict,
922
- quality_findings: dict,
923
- documentation_findings: dict,
924
- ) -> list[QualityGate]:
925
- """Evaluate quality gates based on agent findings."""
926
- gates = []
927
-
928
- # Security gate: no critical issues
929
- sec_gate = QualityGate(
930
- name="Security",
931
- threshold=self.quality_gates["security"],
932
- actual=float(security_findings.get("critical_count", 0)),
933
- critical=True,
934
- )
935
- sec_gate.passed = sec_gate.actual <= sec_gate.threshold
936
- gates.append(sec_gate)
937
-
938
- # Test coverage gate
939
- cov_gate = QualityGate(
940
- name="Test Coverage",
941
- threshold=self.quality_gates["coverage"],
942
- actual=testing_findings.get("coverage", 0.0),
943
- critical=True,
944
- )
945
- cov_gate.passed = cov_gate.actual >= cov_gate.threshold
946
- gates.append(cov_gate)
947
-
948
- # Code quality gate
949
- qual_gate = QualityGate(
950
- name="Code Quality",
951
- threshold=self.quality_gates["quality"],
952
- actual=quality_findings.get("quality_score", 0.0),
953
- critical=True,
954
- )
955
- qual_gate.passed = qual_gate.actual >= qual_gate.threshold
956
- gates.append(qual_gate)
957
-
958
- # Documentation gate
959
- doc_gate = QualityGate(
960
- name="Documentation",
961
- threshold=self.quality_gates["documentation"],
962
- actual=documentation_findings.get("docstring_coverage", 0.0),
963
- critical=False, # Non-critical warning
964
- )
965
- doc_gate.passed = doc_gate.actual >= doc_gate.threshold
966
- gates.append(doc_gate)
967
-
968
- return gates