"""Prompt assembly for design copilot responses.""" from __future__ import annotations from .config import MODES from .index_store import SearchResult SYSTEM_PROMPT = """You are GameMaster Design Copilot, a practical game design assistant. Use retrieved source context when available and cite it by source id in the answer. If no approved source context is provided, explicitly say the response is an ungrounded design pass. Be concrete: propose mechanics, tradeoffs, edge cases, tuning levers, and playtest checks. Do not claim that copyrighted or unapproved material is in the corpus.""" MODE_GUIDANCE = { "brainstorm": "Give 3 to 5 distinct design directions, name the strongest one, and explain why.", "critique": "Find failure modes, confusing rules, pacing risks, and missing player feedback.", "balance": "Focus on incentives, dominant strategies, exploit loops, resource curves, and tunable parameters.", "level_design": "Focus on onboarding, spatial readability, encounter cadence, landmarks, gates, and affordances.", "gm_session": "Make the answer table-ready: scenes, NPC motives, encounter beats, rulings, and fallback prompts.", } def build_context_block(results: list[SearchResult]) -> str: if not results: return "No approved source context was retrieved." blocks: list[str] = [] for index, result in enumerate(results, start=1): chunk = result.chunk blocks.append( "\n".join( [ f"[{index}] source_id={chunk.source_id}", f"title={chunk.title}", f"license={chunk.license}", f"url={chunk.url or 'local'}", f"score={result.score:.3f}", chunk.text, ] ) ) return "\n\n---\n\n".join(blocks) def build_user_prompt( *, mode: str, message: str, project_context: str, results: list[SearchResult], ) -> str: mode_description = MODES.get(mode, MODES["brainstorm"]) mode_guidance = MODE_GUIDANCE.get(mode, MODE_GUIDANCE["brainstorm"]) context_block = build_context_block(results) project_context = project_context or "No project context supplied." return f"""Mode: {mode} Mode purpose: {mode_description} Mode response guidance: {mode_guidance} Project context: {project_context} Retrieved source context: {context_block} User request: {message} Answer with: 1. Direct recommendation 2. Concrete design details 3. Risks and tradeoffs 4. Playtest or validation checks 5. Citations used, if any"""