from rich.console import Console from afk_developer.backends.registry import BackendRegistry from afk_developer.config import Config from afk_developer.grillme.spec_model import TaskSpec console = Console() SYSTEM_PROMPT = """You are a senior software engineer helping to clarify a coding task before execution. Read the task spec carefully and ask 2-3 concise clarifying questions that would help produce a better implementation plan. Focus on: - Ambiguities in the goal/requirements - Missing technical details (error handling, edge cases, formats) - Scope boundaries Return ONLY a JSON array of question objects: [ {"question": "What should the redirect behavior be if the original site is unavailable?", "default": "show an error page"}, {"question": "Should the mirror preserve the original URL path structure?", "default": "yes, preserve paths"} ] If the spec is already clear and needs no further clarification, return: []""" def ask_clarifying_questions(spec: TaskSpec, config: Config) -> list[dict[str, str]]: content = f"""GOAL: {spec.goal} LANGUAGE: {spec.language or "unknown"} FRAMEWORK: {spec.framework or "none"} TEST FRAMEWORK: {spec.test_framework or "none"} CONSTRAINTS: {", ".join(spec.constraints) if spec.constraints else "none"} EXISTING FILES: {spec.auto_detected.existing_files_count} ADDITIONAL NOTES: {spec.additional_context or "none"}""" from afk_developer.utils import extract_json response = ( BackendRegistry(config) .get_reasoner() .complete( system_prompt=SYSTEM_PROMPT, user_prompt=content, temperature=0.3, ) ) config.record_usage(response.usage, role="reasoner") questions = extract_json(response.content) if not isinstance(questions, list): return [] return questions