# /// script # requires-python = ">=3.9" # /// #!/usr/bin/env python3 """ Generate an interactive HTML quality analysis report from report-data.json. Reads the structured report data produced by the report creator and renders a self-contained HTML report with: - Grade + narrative at top - Broken items with fix prompts - Opportunity themes with "Fix This Theme" prompt generation - Expandable strengths - Expandable detailed analysis per dimension - Link to full markdown report Usage: python3 generate-html-report.py {quality-report-dir} [--open] """ from __future__ import annotations import argparse import json import platform import subprocess import sys from pathlib import Path def load_report_data(report_dir: Path) -> dict: """Load report-data.json from the report directory.""" data_file = report_dir / 'report-data.json' if not data_file.exists(): print(f'Error: {data_file} not found', file=sys.stderr) sys.exit(2) return json.loads(data_file.read_text(encoding='utf-8')) def build_fix_prompt(skill_path: str, theme: dict) -> str: """Build a coherent fix prompt for an entire opportunity theme.""" prompt = f"## Task: {theme['name']}\n" prompt += f"Skill path: {skill_path}\n\n" prompt += f"### Problem\n{theme['description']}\n\n" prompt += f"### Fix\n{theme['action']}\n\n" if theme.get('findings'): prompt += "### Specific observations to address:\n\n" for i, f in enumerate(theme['findings'], 1): loc = f"{f['file']}:{f['line']}" if f.get('file') and f.get('line') else f.get('file', '') prompt += f"{i}. **{f['title']}**" if loc: prompt += f" ({loc})" if f.get('detail'): prompt += f"\n {f['detail']}" prompt += "\n" return prompt.strip() def build_broken_prompt(skill_path: str, items: list) -> str: """Build a fix prompt for all broken items.""" prompt = f"## Task: Fix Critical Issues\nSkill path: {skill_path}\n\n" for i, item in enumerate(items, 1): loc = f"{item['file']}:{item['line']}" if item.get('file') and item.get('line') else item.get('file', '') prompt += f"{i}. **[{item.get('severity','high').upper()}] {item['title']}**\n" if loc: prompt += f" File: {loc}\n" if item.get('detail'): prompt += f" Context: {item['detail']}\n" if item.get('action'): prompt += f" Fix: {item['action']}\n" prompt += "\n" return prompt.strip() HTML_TEMPLATE = r"""