demo_conflicts.py 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. #!/usr/bin/env python3
  2. """
  3. Demo: Conflict Detection and Reporting
  4. This demonstrates the unified scraper's ability to detect and report
  5. conflicts between documentation and code implementation.
  6. """
  7. import sys
  8. import json
  9. from pathlib import Path
  10. # Add CLI to path
  11. sys.path.insert(0, str(Path(__file__).parent / 'cli'))
  12. from conflict_detector import ConflictDetector
  13. print("=" * 70)
  14. print("UNIFIED SCRAPER - CONFLICT DETECTION DEMO")
  15. print("=" * 70)
  16. print()
  17. # Load test data
  18. print("📂 Loading test data...")
  19. print(" - Documentation APIs from example docs")
  20. print(" - Code APIs from example repository")
  21. print()
  22. with open('cli/conflicts.json', 'r') as f:
  23. conflicts_data = json.load(f)
  24. conflicts = conflicts_data['conflicts']
  25. summary = conflicts_data['summary']
  26. print(f"✅ Loaded {summary['total']} conflicts")
  27. print()
  28. # Display summary
  29. print("=" * 70)
  30. print("CONFLICT SUMMARY")
  31. print("=" * 70)
  32. print()
  33. print(f"📊 **Total Conflicts**: {summary['total']}")
  34. print()
  35. print("**By Type:**")
  36. for conflict_type, count in summary['by_type'].items():
  37. if count > 0:
  38. emoji = "📖" if conflict_type == "missing_in_docs" else "💻" if conflict_type == "missing_in_code" else "⚠️"
  39. print(f" {emoji} {conflict_type}: {count}")
  40. print()
  41. print("**By Severity:**")
  42. for severity, count in summary['by_severity'].items():
  43. if count > 0:
  44. emoji = "🔴" if severity == "high" else "🟡" if severity == "medium" else "🟢"
  45. print(f" {emoji} {severity.upper()}: {count}")
  46. print()
  47. # Display detailed conflicts
  48. print("=" * 70)
  49. print("DETAILED CONFLICT REPORTS")
  50. print("=" * 70)
  51. print()
  52. # Group by severity
  53. high = [c for c in conflicts if c['severity'] == 'high']
  54. medium = [c for c in conflicts if c['severity'] == 'medium']
  55. low = [c for c in conflicts if c['severity'] == 'low']
  56. # Show high severity first
  57. if high:
  58. print("🔴 **HIGH SEVERITY CONFLICTS** (Requires immediate attention)")
  59. print("-" * 70)
  60. for conflict in high:
  61. print()
  62. print(f"**API**: `{conflict['api_name']}`")
  63. print(f"**Type**: {conflict['type']}")
  64. print(f"**Issue**: {conflict['difference']}")
  65. print(f"**Suggestion**: {conflict['suggestion']}")
  66. if conflict['docs_info']:
  67. print(f"\n**Documented as**:")
  68. print(f" Signature: {conflict['docs_info'].get('raw_signature', 'N/A')}")
  69. if conflict['code_info']:
  70. print(f"\n**Implemented as**:")
  71. params = conflict['code_info'].get('parameters', [])
  72. param_str = ', '.join(f"{p['name']}: {p.get('type_hint', 'Any')}" for p in params if p['name'] != 'self')
  73. print(f" Signature: {conflict['code_info']['name']}({param_str})")
  74. print(f" Return type: {conflict['code_info'].get('return_type', 'None')}")
  75. print(f" Location: {conflict['code_info'].get('source', 'N/A')}:{conflict['code_info'].get('line', '?')}")
  76. print()
  77. # Show medium severity
  78. if medium:
  79. print("🟡 **MEDIUM SEVERITY CONFLICTS** (Review recommended)")
  80. print("-" * 70)
  81. for conflict in medium[:3]: # Show first 3
  82. print()
  83. print(f"**API**: `{conflict['api_name']}`")
  84. print(f"**Type**: {conflict['type']}")
  85. print(f"**Issue**: {conflict['difference']}")
  86. if conflict['code_info']:
  87. print(f"**Location**: {conflict['code_info'].get('source', 'N/A')}")
  88. if len(medium) > 3:
  89. print(f"\n ... and {len(medium) - 3} more medium severity conflicts")
  90. print()
  91. # Example: How conflicts appear in final skill
  92. print("=" * 70)
  93. print("HOW CONFLICTS APPEAR IN SKILL.MD")
  94. print("=" * 70)
  95. print()
  96. example_conflict = high[0] if high else medium[0] if medium else conflicts[0]
  97. print("```markdown")
  98. print("## 🔧 API Reference")
  99. print()
  100. print("### ⚠️ APIs with Conflicts")
  101. print()
  102. print(f"#### `{example_conflict['api_name']}`")
  103. print()
  104. print(f"⚠️ **Conflict**: {example_conflict['difference']}")
  105. print()
  106. if example_conflict.get('docs_info'):
  107. print("**Documentation says:**")
  108. print("```")
  109. print(example_conflict['docs_info'].get('raw_signature', 'N/A'))
  110. print("```")
  111. print()
  112. if example_conflict.get('code_info'):
  113. print("**Code implementation:**")
  114. print("```python")
  115. params = example_conflict['code_info'].get('parameters', [])
  116. param_strs = []
  117. for p in params:
  118. if p['name'] == 'self':
  119. continue
  120. param_str = p['name']
  121. if p.get('type_hint'):
  122. param_str += f": {p['type_hint']}"
  123. if p.get('default'):
  124. param_str += f" = {p['default']}"
  125. param_strs.append(param_str)
  126. sig = f"def {example_conflict['code_info']['name']}({', '.join(param_strs)})"
  127. if example_conflict['code_info'].get('return_type'):
  128. sig += f" -> {example_conflict['code_info']['return_type']}"
  129. print(sig)
  130. print("```")
  131. print()
  132. print("*Source: both (conflict)*")
  133. print("```")
  134. print()
  135. # Key takeaways
  136. print("=" * 70)
  137. print("KEY TAKEAWAYS")
  138. print("=" * 70)
  139. print()
  140. print("✅ **What the Unified Scraper Does:**")
  141. print(" 1. Extracts APIs from both documentation and code")
  142. print(" 2. Compares them to detect discrepancies")
  143. print(" 3. Classifies conflicts by type and severity")
  144. print(" 4. Provides actionable suggestions")
  145. print(" 5. Shows both versions transparently in the skill")
  146. print()
  147. print("⚠️ **Common Conflict Types:**")
  148. print(" - **Missing in docs**: Undocumented features in code")
  149. print(" - **Missing in code**: Documented but not implemented")
  150. print(" - **Signature mismatch**: Different parameters/types")
  151. print(" - **Description mismatch**: Different explanations")
  152. print()
  153. print("🎯 **Value:**")
  154. print(" - Identifies documentation gaps")
  155. print(" - Catches outdated documentation")
  156. print(" - Highlights implementation differences")
  157. print(" - Creates single source of truth showing reality")
  158. print()
  159. print("=" * 70)
  160. print("END OF DEMO")
  161. print("=" * 70)