from importlib.resources import files from viano_bug_analysis.lifecycle.storage import json_bytes from viano_bug_analysis.llm import PromptBuilder from .hypothesis_contracts import output_schema PROMPT_VERSION = "hypotheses_v1" class HypothesisPromptBuilder(PromptBuilder): def build(self, context): schema = output_schema(context["policy"]) if context.get('joint_retained'): retained=context['joint_retained'];array=schema['properties']['hypotheses'] array.update(minItems=retained['count'],maxItems=retained['count']) array['prefixItems']=[{'const':retained['proposals'][str(i)]} if str(i) in retained['proposals'] else {'$ref':'#/$defs/proposal'} for i in range(retained['count'])] version = context.get('prompt_version', PROMPT_VERSION) model_context = context encode = lambda value: json_bytes(value).decode("utf-8") if version in {'hypotheses_v2','hypotheses_v3','hypotheses_v4'}: from .model_context import compact_context, model_json if version == "hypotheses_v4": from .phase_selection import select_context model_context = select_context(context,"hypotheses") import copy model_context = copy.deepcopy(model_context) model_context.get("case_context", {}).pop("joint_generation", None) model_context = compact_context(model_context) encode = model_json if version in {"hypotheses_v3","hypotheses_v4"}: from .json_consolidation import consolidate model_context = consolidate(model_context) return {"prompt_version": version, "privacy": "configured", "output_schema": schema, "messages": [{"role": "system", "content": files("viano_bug_analysis.llm.prompts").joinpath(version + ".txt").read_text(encoding="utf-8") + ("\nPreserve joint_retained.proposals exactly at their zero-based positions. Generate ONLY the other positions; return the full array for deterministic merging/validation. Retained proposals were explicitly reviewed; do not rewrite or reorder them." if context.get("joint_retained") else "")}, {"role": "user", "content": encode({"task": "generate_hypotheses", "input": model_context, "output_schema": schema})}]}