from __future__ import annotations import json from typing import Any from .reference_catalog import format_reference_cases, profile_guide, select_reference_cases, selection_payload TYPE_GUIDE = """Choose exactly one primary type: - context: system and external actors; answers what is inside/outside. - architecture/container/component: static responsibilities and dependencies at one abstraction level. - deployment/network: runtime nodes, zones, regions, trust or network boundaries. - data-flow: where data originates, transforms, persists, and exits. - sequence: time-ordered interactions for one scenario; every edge needs order. - flow: decisions and procedural steps. - state: valid states and transitions. - erd: data entities, keys, and relationships. - dependency: dense structural dependencies; use sparingly. - concept: comparison or explanatory model when implementation detail is not the point.""" def _sample_evidence_line(context: dict[str, Any]) -> int: current = context.get("current_section") or {} start = int(current.get("start_line") or context.get("context_range", {}).get("start_line") or 1) end = int(current.get("end_line") or context.get("context_range", {}).get("end_line") or start) for item in context.get("context_lines", []): if not isinstance(item, dict): continue line = item.get("line") text = str(item.get("text", "")).strip() if not isinstance(line, int) or not (start <= line <= end): continue if text and not text.startswith("#") and not text.startswith("