from __future__ import annotations from django.core.management.base import BaseCommand, CommandError from control_plane.resources.models import Resource from model_router.providers import SolProvider from model_router.router import ModelRequestContract from project_brain.planning import PlanValidationError, parse_project_plan_response class Command(BaseCommand): help = "Opt-in smoke test: ask Sol on Spark for a structured project plan and validate it." def add_arguments(self, parser): parser.add_argument("goal") def handle(self, *args, **options): resource = Resource.objects.filter(provider="opencode", is_active=True).first() if resource is None: raise CommandError("No Sol/opencode resource configured. Run seed_spark_resources first.") prompt = ( "Return only valid JSON. No markdown. No commentary. The JSON must match this exact shape: " "{\"project_plan\":{\"goal\":str,\"scope\":str,\"acceptance_criteria\":[str]," "\"milestones\":[{\"key\":str,\"title\":str,\"goal\":str,\"features\":[{" "\"key\":str,\"title\":str,\"description\":str,\"acceptance_criteria\":[str]," "\"tasks\":[{\"id\":str,\"goal\":str,\"acceptance_criteria\":[str]," "\"dependencies\":[str]}]}]}]}}. Include at least one milestone, one feature, and one task. Goal: " + options["goal"] ) response = SolProvider(resource).complete(ModelRequestContract(purpose="PLANNING", prompt=prompt, token_budget=4000)) try: contract = parse_project_plan_response(response.content) except PlanValidationError as exc: raise CommandError(f"Sol returned invalid plan: {exc}") from exc self.stdout.write(self.style.SUCCESS(f"Validated Sol plan: {contract.goal}"))