""" Project Creation Service Module for Archon This module handles the complex project creation workflow including AI-assisted documentation generation and progress tracking. """ # Removed direct logging import - using unified config from typing import Any from src.server.repositories.base_repository import BaseRepository from ...config.logfire_config import get_logger logger = get_logger(__name__) class ProjectCreationService(BaseRepository): """Service class for advanced project creation with AI assistance""" def __init__(self, supabase_client=None): """Initialize with optional supabase client""" super().__init__(supabase_client) async def create_project_with_ai( self, progress_id: str, title: str, description: str | None = None, github_repo: str | None = None, **kwargs, ) -> tuple[bool, dict[str, Any]]: """ Create a project with AI-assisted documentation generation. Args: progress_id: Progress tracking identifier title: Project title description: Project description github_repo: GitHub repository URL **kwargs: Additional project data Returns: Tuple of (success, result_dict) """ logger.info( f"🏗️ [PROJECT-CREATION] Starting create_project_with_ai for progress_id: {progress_id}, title: {title}" ) project_data: dict[str, Any] = { "title": title, "description": description, "github_repo": github_repo, "status": "planning", "docs": {}, "features": [], "data": {}, } def _query(): return self.supabase_client.table("archon_projects").insert(project_data).execute() success, result = self.execute_query(query_func=_query, error_context="DB operation logged error") if success: # TODO: Extract properties via 'result["data"]' as per original logic return True, {"data": result["data"]} return False, result async def _generate_ai_documentation( self, progress_id: str, project_id: str, title: str, description: str | None, github_repo: str | None, ) -> bool: """ Generate AI documentation for the project. Returns: True if successful, False otherwise """ try: # Check if LLM provider is configured from ..credential_service import credential_service provider_config = await credential_service.get_active_provider("llm") if not provider_config: # No LLM provider configured, skip AI documentation return False # Import DocumentAgent (lazy import to avoid startup issues) from ...agents.document_agent import DocumentAgent # Initialize DocumentAgent document_agent = DocumentAgent() # Generate comprehensive PRD using conversation prd_request = ( f"Create a PRD document titled '{title} - Product Requirements Document' for a project called '{title}'" ) if description: prd_request += f" with the following description: {description}" if github_repo: prd_request += f" (GitHub repo: {github_repo})" # Create a progress callback for the document agent async def agent_progress_callback(update_data): pass # Progress tracking removed # Run the document agent to create PRD agent_result = await document_agent.run_conversation( user_message=prd_request, project_id=project_id, user_id="system", progress_callback=agent_progress_callback, ) if agent_result.success: return True else: return False except Exception as ai_error: logger.warning(f"AI generation failed, continuing with basic project: {ai_error}") return False