""" Code Review Schema GitHub PR review-style annotation with inline diff commenting, file-level ratings, and overall verdict. Features: - Click on diff lines in CodingTraceDisplay to add comments - Per-comment category (bug, style, suggestion, security, question) - File-level correctness and quality ratings - Overall verdict (approve, request_changes, comment_only) """ import json import logging from typing import Dict, Any, Tuple, List from .identifier_utils import ( safe_generate_layout, generate_element_identifier, generate_validation_attribute, escape_html_content, generate_layout_attributes, ) logger = logging.getLogger(__name__) DEFAULT_CATEGORIES = ["bug", "style", "suggestion", "security", "question"] DEFAULT_VERDICTS = ["approve", "request_changes", "comment_only"] DEFAULT_RATING_DIMS = ["correctness", "quality"] def generate_code_review_layout( annotation_scheme: Dict[str, Any], ) -> Tuple[str, List[Tuple[str, str]]]: """Generate HTML for a code review annotation interface. Args: annotation_scheme: Configuration dict. Required keys: ``name``, ``description``. Optional: ``comment_categories``, ``verdict_options``, ``file_rating_dimensions``. Returns: ``(html, keybindings)`` tuple. """ return safe_generate_layout(annotation_scheme, _generate_internal) def _generate_internal( annotation_scheme: Dict[str, Any], ) -> Tuple[str, List[Tuple[str, str]]]: schema_name = annotation_scheme["name"] description = annotation_scheme["description"] categories = annotation_scheme.get("comment_categories", DEFAULT_CATEGORIES) verdicts = annotation_scheme.get("verdict_options", DEFAULT_VERDICTS) rating_dims = annotation_scheme.get("file_rating_dimensions", DEFAULT_RATING_DIMS) layout_attrs = generate_layout_attributes(annotation_scheme) validation = generate_validation_attribute(annotation_scheme) identifiers = generate_element_identifier(schema_name, schema_name, "hidden") esc_schema = escape_html_content(schema_name) config_json = json.dumps({ "categories": categories, "verdicts": verdicts, "rating_dims": rating_dims, }) # Build verdict radios verdict_html = "" for v in verdicts: label = v.replace("_", " ").title() css = f"cr-verdict-{v}" verdict_html += ( f'' ) # Build category options cat_options = "".join( f'' for c in categories ) html = f"""
""" logger.info( f"Successfully generated code_review layout for {schema_name} " f"({len(categories)} categories, {len(verdicts)} verdicts)" ) return html, [] # No keybindings